Optimize Stop Order
Find optimal ordering for a list of stops (TSP)
POST
/routing/tspOptimize the order of a list of stops using Traveling Salesman Problem (TSP) algorithms. Similar to Single Route but finds the optimal ordering rather than just calculating the route for a given order.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
stops | Coordinates[] | Yes | Unordered list of stops to optimize |
start | Coordinates | No | Fixed starting point |
end | Coordinates | No | Fixed ending point |
roundTrip | boolean | No | Return to starting point (default: false) |
departure | ISO8601 | No | Departure time for traffic calculation |
Coordinates
| Field | Type | Required | Description |
|---|---|---|---|
lat | number | Yes | Latitude |
lng | number | Yes | Longitude |
Example Response
Response Fields
| Field | Type | Description |
|---|---|---|
geometry | string | Encoded polyline of the optimized route |
distance | number | Total distance in meters |
duration | number | Total duration in seconds |
orderedStops | Coordinates[] | Stops in optimized order |
legs | RouteLeg[] | Per-segment details |
Route Leg
Each leg represents the segment between consecutive stops:
| Field | Type | Description |
|---|---|---|
distance | number | Segment distance in meters |
duration | number | Segment duration in seconds |
Fixed Start/End Points
By default, the algorithm determines the optimal start and end points. You can constrain these:
Fixed Start Only
Route starts at the specified point, ends at the optimal location.
Fixed Start and End
Route starts and ends at the specified points.
Round Trip
Route returns to the starting point after visiting all stops.
Use Cases
- Delivery Route Planning: Optimize stop sequence for deliveries
- Field Service: Plan technician visits in optimal order
- Sales Routes: Minimize travel time between customer visits
- Multi-Stop Navigation: Find best order for multiple destinations