Skip to content

Optimization

The Optimized Route service provides a quick computation of time and distance between a set of location sources and location targets and returns them in an optimized route order, along with the shape.

Inputs of the optimized route

The optimized route request run locally takes the form of json={}, where the JSON inputs inside the {} includes location information (at least four locations), as well as the name and options for the costing model

Here is an example of an Optimized Route scenario:

Given a list of cities and the distances and times between each pair, a salesperson wants to visit each city one time by taking the most optimized route and end at a destination (either return to origin or a different destination)

json
{ "locations": [ { "lat": 40.042072, "lon": -76.306572 }, { "lat": 39.992115, "lon": -76.781559 }, { "lat": 39.984519, "lon": -76.695600 }, { "lat": 39.996586, "lon": -76.769028 }, { "lat": 39.984322, "lon": -76.706672 } ], "costing": "auto", "units": "miles" }
ParameterLocationRequiredDescription
tokenQuery Param✅ YesAPI authentication token. Required, otherwise the API will return 401 Token required.
locationsBody JSON✅ YesArray of coordinates (lat, lon). At least 2 locations must be provided.
costingBody JSON✅ YesTravel mode. Options: auto, pedestrian, bicycle.
unitsBody JSON❌ NoDistance units. Options: miles (default) or kilometers.

Outputs of the optimized route service

These are the results of a request to the Optimized Route service.

ItemDescription
optimized_routeReturns an optimized route path from point 'a' to point 'n'. Given a list of locations, an optimized route with stops at each intermediate location exactly one time, always starting at the first location in the list and ending at the last location.
locationsThe specified array of lat/lngs from the input request. The first and last locations in the array will remain the same as the input request. The intermediate locations may be returned reordered in the response. Due to the reordering of the intermediate locations, an original_index is also part of the locations object within the response. This is an identifier of the location index that will allow a user to easily correlate input locations with output locations.
unitsDistance units for output. Allowable unit types are mi (miles) and km (kilometers). If no unit type is specified, the units default to kilometers.
warnings (optional)This array may contain warning objects informing about deprecated request parameters, clamped values etc.