Skip to content
GuidesBlogPlaygroundDashboard

Optimize route through waypoints

OptimizeResult Optimize.Create(OptimizeCreateParamsparameters, CancellationTokencancellationToken = default)
POST/api/v1/optimize

Optimize route through waypoints

ParametersExpand Collapse
OptimizeCreateParams parameters
required IReadOnlyList<Waypoint> waypoints

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

required Double Lat

Latitude in decimal degrees (-90 to 90)

maximum90
minimum-90
required Double Lng

Longitude in decimal degrees (-180 to 180)

maximum180
minimum-180
string format

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

Mode mode

Body param: Travel mode (default: auto)

"auto"Auto
"foot"Foot
"bicycle"Bicycle
Boolean roundtrip

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

ReturnsExpand Collapse
class OptimizeResult: A class that can be one of several variants.union

Optimization response — either a completed FeatureCollection with the optimized route, or an async job reference to poll.

class OptimizeCompletedResult:

Completed optimization result as a GeoJSON FeatureCollection. Each Feature is a waypoint in optimized visit order. Top-level fields provide summary statistics.

required IReadOnlyList<Feature> Features

Waypoints in optimized visit order

required GeoJsonGeometry Geometry

GeoJSON Geometry object per RFC 7946. Coordinates use [longitude, latitude] order. 3D coordinates [lng, lat, elevation] are used for elevation endpoints.

required Coordinates Coordinates

Coordinates array. Nesting depth varies by geometry type: Point = [lng, lat], LineString = [[lng, lat], ...], Polygon = [[[lng, lat], ...], ...], etc.

One of the following:
IReadOnlyList<Double>
IReadOnlyList<IReadOnlyList<Double>>
IReadOnlyList<IReadOnlyList<IReadOnlyList<Double>>>
IReadOnlyList<IReadOnlyList<IReadOnlyList<IReadOnlyList<Double>>>>
required Type Type

Geometry type

One of the following:
"Point"Point
"LineString"LineString
"Polygon"Polygon
"MultiPoint"MultiPoint
"MultiLineString"MultiLineString
"MultiPolygon"MultiPolygon
required Properties Properties
required Double CostS

Travel time in seconds from the previous waypoint to this one (0 for the first waypoint)

required Double CumulativeCostS

Cumulative travel time in seconds from the start to this waypoint

required Long WaypointIndex

Position of this waypoint in the optimized visit order (0-based)

required Type Type
required string Optimization

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

required Boolean Roundtrip

Whether the route returns to the starting waypoint

required Double TotalCostS

Total travel time for the optimized route in seconds

required Type Type
class OptimizeProcessingResult:

Async optimization in progress. Poll GET /api/v1/optimize/{job_id} until the status changes to completed or failed.

required string JobID

Job ID for polling the result

required Status Status

Always processing

Optimize route through waypoints

OptimizeCreateParams parameters = new()
{
    Waypoints =
    [
        new()
        {
            Lat = 48.8566,
            Lng = 2.3522,
        },
        new()
        {
            Lat = 48.8606,
            Lng = 2.3376,
        },
        new()
        {
            Lat = 48.8584,
            Lng = 2.2945,
        },
    ],
};

var optimizeResult = await client.Optimize.Create(parameters);

Console.WriteLine(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"
}