Skip to content
GuidesPlaygroundDashboard

Optimize route through waypoints

optimize.create(**kwargs) -> OptimizeResult
POST/api/v1/optimize

Optimize route through waypoints

ParametersExpand Collapse
waypoints: GeoJsonGeometry { coordinates, type }

Waypoints to visit (GeoJSON MultiPoint geometry, minimum 2 points)

coordinates: Array[Float] | Array[Array[Float]] | Array[Array[Array[Float]]] | Array[Array[Array[Array[Float]]]]

GeoJSON coordinates array (nesting depth varies by geometry type)

One of the following:
Array[Float]
Array[Array[Float]]
Array[Array[Array[Float]]]
Array[Array[Array[Array[Float]]]]
type: :Point | :LineString | :Polygon | 3 more
One of the following:
:Point
:LineString
:Polygon
:MultiPoint
:MultiLineString
:MultiPolygon
mode: :auto | :foot | :bicycle

Travel mode (default: auto)

One of the following:
:auto
:foot
:bicycle
roundtrip: bool

Whether route returns to start (default: true)

ReturnsExpand Collapse
OptimizeResult = OptimizeCompletedResult { geometry, properties, status, type } | OptimizeProcessingResult { job_id, status }

Optimization response — either a completed GeoJSON Feature route or an async job reference

One of the following:
class OptimizeCompletedResult { geometry, properties, status, type }

Completed optimization — GeoJSON Feature with optimized route

geometry: GeoJsonGeometry { coordinates, type }
coordinates: Array[Float] | Array[Array[Float]] | Array[Array[Array[Float]]] | Array[Array[Array[Array[Float]]]]

GeoJSON coordinates array (nesting depth varies by geometry type)

One of the following:
Array[Float]
Array[Array[Float]]
Array[Array[Array[Float]]]
Array[Array[Array[Array[Float]]]]
type: :Point | :LineString | :Polygon | 3 more
One of the following:
:Point
:LineString
:Polygon
:MultiPoint
:MultiLineString
:MultiPolygon
properties: { distance, duration, waypoint_order}
distance: Float

Total distance in meters

duration: Float

Estimated duration in seconds

waypoint_order: Array[Integer]

Optimized waypoint ordering

status: :completed

Job status

type: :Feature
class OptimizeProcessingResult { job_id, status }

Async optimization in progress — poll with the job_id

job_id: String

Job ID for polling

status: :processing

Job status

Optimize route through waypoints

require "plaza"

plaza = Plaza::Client.new(
  api_key: "My API Key",
  environment: "local" # defaults to "production"
)

optimize_result = plaza.optimize.create(waypoints: {coordinates: [0], type: :Point})

puts(optimize_result)
Returns Examples