Skip to content
GuidesBlogPlaygroundDashboard

Optimize route through waypoints

$client->optimize->create(list<Waypoint> waypoints, ?string format, ?Mode mode, ?bool roundtrip): OptimizeResult
POST/api/v1/optimize

Optimize route through waypoints

ParametersExpand Collapse
waypoints: list<Waypoint>

Waypoints to visit in optimized order (2-50 points)

format?:optional string

Response format: json (default), geojson, csv, ndjson

mode?:optional Mode

Travel mode (default: auto)

roundtrip?:optional bool

Whether the route should return to the starting waypoint (default: true)

ReturnsExpand Collapse
One of the following:
list<Feature> features

Waypoints in optimized visit order

string optimization

Optimization method used (e.g. nearest_neighbor, 2opt)

bool roundtrip

Whether the route returns to the starting waypoint

float totalCostS

Total travel time for the optimized route in seconds

Type type
string jobID

Job ID for polling the result

Status status

Always processing

Optimize route through waypoints

<?php

require_once dirname(__DIR__) . '/vendor/autoload.php';

$client = new Client(apiKey: 'My API Key', environment: 'local');

$optimizeResult = $client->optimize->create(
  waypoints: [
    ['lat' => 48.8566, 'lng' => 2.3522],
    ['lat' => 48.8606, 'lng' => 2.3376],
    ['lat' => 48.8584, 'lng' => 2.2945],
  ],
  format: 'format',
  mode: 'auto',
  roundtrip: false,
);

var_dump($optimizeResult);
{
  "features": [
    {
      "geometry": {
        "coordinates": [
          2.3522,
          48.8566
        ],
        "type": "Point"
      },
      "properties": {
        "cost_s": 0,
        "cumulative_cost_s": 0,
        "waypoint_index": 0
      },
      "type": "Feature"
    }
  ],
  "optimization": "optimization",
  "roundtrip": true,
  "total_cost_s": 0,
  "type": "FeatureCollection"
}
Returns Examples
{
  "features": [
    {
      "geometry": {
        "coordinates": [
          2.3522,
          48.8566
        ],
        "type": "Point"
      },
      "properties": {
        "cost_s": 0,
        "cumulative_cost_s": 0,
        "waypoint_index": 0
      },
      "type": "Feature"
    }
  ],
  "optimization": "optimization",
  "roundtrip": true,
  "total_cost_s": 0,
  "type": "FeatureCollection"
}