Waypoint Optimization
Purpose
This endpoint optimizes a provided waypoints sequence based on road network distances. Sequence is ordered to form the fastest route.
Service Limitations
- The maximum amount of waypoints sent in the request is 12.
- The waypoint limit includes origin and destination.
- The service assumes Time Windows are within 24 hours from
departAt
. Because of that, Time Windows ending beforedepartAt
are automatically moved to the next day if possible.
Check our Pricing and Contact Sales to enable higher limits for the amount of waypoints.
Run this endpoint
You can easily run this and other endpoints. Go to the TomTom API Explorer page and follow the directions.
Types
The following data table describes the complex data types that can be used in the Waypoint Optimization service.
Type | Description |
---|---|
| A date and time specified in RFC 3339 format with the literal „Z”, or a time zone offset.
|
| A time specified in the format HH:MM. Time is based on a 24 hour system.
|
Feature usage
Legend
Symbol | Meaning |
---|---|
✔ | These features can be used together. Check corresponding field descriptions for usage details. |
★ | Feature has to be used in combination with the marked feature. Check corresponding field descriptions for usage details. |
✘ | Features can't be used together. |
— | Not applicable. |
Features
When I use <row>, can I use <column>? | Waypoint Constraints | Group Constraints | Time Windows | Depart At | Traffic | Service Time | Importance |
---|---|---|---|---|---|---|---|
Waypoint Constraints | — | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
Group Constraints | ✔ | — | ✔ | ✔ | ✔ | ✔ | ✘ |
Time Windows | ✔ | ✔ | — | ★ | ✔ | ✔ | ✔ |
Depart At | ✔ | ✔ | ✔ | — | ✔ | ✔ | ✔ |
Traffic | ✔ | ✔ | ✔ | ✔ | — | ✔ | ✔ |
Service Time | ✔ | ✔ | ✔ | ✔ | ✔ | — | ✔ |
Importance | ✔ | ✘ | ★ | ★ | ✔ | ✔ | — |
Request data
HTTPS method: POST
- Constants and parameters enclosed in curly brackets { } must be replaced with their values.
- Please see the following Request parameters section with the required and optional parameters tables for their values. The generic request format is as follows.
- Note: the service requires an explicit
Content-Type
header set toapplication/json
.
URL format
https://{baseURL}/routing/waypointoptimization/{versionNumber}?key={Your_API_Key}
curl command format
1curl -v -XPOST -H "Content-Type: application/json" -d2'{3 "waypoints": [{4 "point": {5 "latitude": waypoint_latitude,6 "longitude": waypoint_longitude7 },8 "timeWindows":[{9 "openingHour": "hour_string",10 "closingHour": "hour_string"11 }12 ],13 "serviceTimeInSeconds": service_time_s,14 "importance": waypoint_importance_value15 },16 ...17 ],18 "options": {19 "travelMode": "type_of_vehicle",20 "vehicleMaxSpeed": max_speed_kph,21 "vehicleWeight": max_weight_kg,22 "vehicleAxleWeight": max_axle_weight_kg,23 "vehicleLength": vehicle_length_m,24 "vehicleWidth": vehicle_width_m,25 "vehicleHeight": vehicle_height_m,26 "vehicleCommercial": is_vehicle_commercial,27 "vehicleLoadType": ["load_type", ...],28 "vehicleAdrTunnelRestrictionCode": "tunnel_restriction_code",29 "outputExtensions": ["travelTimes", "routeLengths"],30 "traffic": "historical" | "live",31 "departAt": dateTime | "any" | "now",32 "waypointConstraints": {33 "originIndex": index_of_origin_endpoint,34 "destinationIndex": index_of_destination_endpoint,35 "visitingOrders": [[index_of_the_first_waypoint, index_of_the_second_waypoint], ...]36 },37 "groupConstraints": {38 "groups": [39 {40 "includedPointIndexes": [waypoint_indexes_included_in_group]41 },42 ...43 ],44 "groupOrders": [[group_indexes]]45 }46 }47}'48'https://{baseURL}/routing/waypointoptimization/{versionNumber}?key={Your_API_Key}'
Request headers
The following table describes HTTP request headers of particular interest to Waypoint Optimization service clients.
Required headers | Description |
---|---|
Content-Type | Specifies the MIME type of the body of the request. |
Optional headers | Description |
---|---|
Tracking-ID | Specifies an identifier for the request.
Value: An |
Request parameters
The following table describes the parameters that can be used in a request.
- Required parameters must be used or the call will fail.
- Optional parameters may be used.
- The order of request parameters is not important.
Note: There are no optional parameters in this endpoint.
Required parameters | Description |
---|---|
| Base URL for calling the API.
|
| Service version number. |
| An API Key valid for the requested service. |
POST request body
1{2 "waypoints": [{3 "point": {4 "latitude": waypoint_latitude,5 "longitude": waypoint_longitude6 },7 "timeWindows":[{8 "openingHour": "hour_string",9 "closingHour": "hour_string"10 }11 ],12 "serviceTimeInSeconds": service_time_s,13 "importance": waypoint_importance_value14 }15 ...16 ],17 "options": {18 "travelMode": "type_of_vehicle",19 "vehicleMaxSpeed": max_speed_kph,20 "vehicleWeight": max_weight_kg,21 "vehicleAxleWeight": max_axle_weight_kg,22 "vehicleLength": vehicle_length_m,23 "vehicleWidth": vehicle_width_m,24 "vehicleHeight": vehicle_height_m,25 "vehicleCommercial": is_vehicle_commercial,26 "vehicleLoadType": ["load_type", ...],27 "vehicleAdrTunnelRestrictionCode": "tunnel_restriction_code",28 "outputExtensions": ["travelTimes", "routeLengths"],29 "traffic": "historical" | "live",30 "departAt": dateTime | "any" | "now",31 "waypointConstraints" : {32 "originIndex": index_of_origin_endpoint,33 "destinationIndex": index_of_destination_endpoint,34 "visitingOrders": [[index_of_the_first_waypoint, index_of_the_second_waypoint], ...]35 },36 "groupConstraints": {37 "groups": [38 {39 "includedPointIndexes": [waypoint_indexes_included_in_group]40 },41 ...42 ],43 "groupOrders": [[group_indexes]]44 }45 }46}
Request fields
The following table describes the fields that can be used in a request body.
Primary fields | |
---|---|
Field | Description |
| A list of waypoints that the Waypoint Optimization Service will use as
input, and then optimize the order of the waypoints. |
| Object containing parameters refining route construction. |
waypoint object | |
| Point representing the waypoint's geographic coordinates. |
| List of time windows defined for the point. Field is not required. |
| The time provided in seconds spent active at a waypoint. Those are
planned activities, such as loading, unloading, delivering a parcel, etc. |
| Specifying |
point object | |
| Latitude coordinate of the point. |
| Longitude coordinate of the point. |
timeWindow object | |
| Opening time of the point. The required format is hour. |
| Closing time of the point. The required format is hour. |
options object | |
| Form of transport.
Field is not required. |
| Maximum speed of the vehicle in km/h.
Field is not required. |
| Vehicle weight in kg. A value of |
| Vehicle axle weight in kg. A value of |
| Vehicle length in meters. A value of |
| Vehicle width in meters. A value of |
| Vehicle height in meters. A value of |
| Is the vehicle used commercially? Vehicles used for commercial purposes may
not be allowed to drive on some roads. |
| List of cargo classifications of hazardous materials transported that
are restricted from some roads.
For routing in all other countries use generic classifications:
Possible values:
Note:
Field is not required. |
| ADR tunnel restrictions. If
Possible values:
Note:
Reference: Field is not required. |
| Response extensions. A list of additional information that will be
returned in the response.
Field is not required. |
| Decides how traffic is considered for computing routes.
Field is not required. |
| The date and time of departure from the origin point.
Possible values:
Field is not required. |
| Optimization guidelines and constraints for waypoints. |
| Optimization guidelines and constraints for groups of waypoints. |
waypointConstraints object | |
| Index of a waypoint (in the waypoints array) used as the origin for the
route. |
| Index of a waypoint (in the waypoints array) used as the destination for
the route. |
| Defines a list of ordered pairs (A, B), where waypoint with index A will
always be in the output before waypoint indexed B. Other points can be
between points in the loose sequence.
Default value: |
groupConstraints object | |
| List of group definitions.
Default value: |
| Defines the order in which groups have to occur in the output. |
group object |
| Waypoint indexes that will create a group. |
Response data
Response body
The following JSON code block example demonstrates a successful response from the API server.
1{2 "optimizedOrder": [0, 2, 1, 3],3 "excludedWaypoints": [4],4 "summary": {5 "routeSummary": {6 "originIndex": 0,7 "destinationIndex": 3,8 "lengthInMeters": 2500,9 "travelTimeInSeconds": 150,10 "waitingTimeInSeconds": 0,11 "serviceTimeInSeconds": 360,12 "departureTime": "2022-05-01T08:00:00-08:00",13 "arrivalTime": "2022-05-01T08:08:30-08:00"14 },15 "legSummaries": [16 {17 "originIndex": 0,18 "destinationIndex": 2,19 "lengthInMeters": 1000,20 "travelTimeInSeconds": 60,21 "waitingTimeInSeconds": 0,22 "serviceTimeInSeconds": 120,23 "departureTime": "2022-05-01T08:02:00-08:00",24 "arrivalTime": "2022-05-01T08:03:00-08:00"25 },26 {27 "originIndex": 2,28 "destinationIndex": 1,29 "lengthInMeters": 500,30 "travelTimeInSeconds": 30,31 "waitingTimeInSeconds": 0,32 "serviceTimeInSeconds": 60,33 "departureTime": "2022-05-01T08:04:00-08:00",34 "arrivalTime": "2022-05-01T08:04:30-08:00"35 },36 {37 "originIndex": 1,38 "destinationIndex": 3,39 "lengthInMeters": 1000,40 "travelTimeInSeconds": 60,41 "waitingTimeInSeconds": 0,42 "serviceTimeInSeconds": 180,43 "departureTime": "2022-05-01T08:07:30-08:00",44 "arrivalTime": "2022-05-01T08:08:30-08:00"45 }46 ]47 }48}
Response header
The following table lists HTTP response headers of particular interest to Fuel Prices service clients.
Header | Description |
---|---|
Tracking-ID | An identifier for the request. If the Tracking-ID header was specified, it
is replicated in the response. Otherwise, it is generated automatically
by the service. It is only meant to be used for support and does not
involve tracking of you or your users in any form. |
Response fields
The following table describes all of the fields that can appear in a response.
Primary fields | |
---|---|
Field | Description |
| Optimized sequence of original waypoint indexes. |
| List of indexes excluded from the |
| Contains additional information about the route created by optimized sequence. |
summary object | |
Field | Description |
| Contains a summary about the route from the start to the end. |
| Contains a summary about routes between waypoints. |
routeSummary object | |
Field | Description |
| The origin index of the described route. |
| The destination index of the described route. |
| Distance in meters between origin and destination indices. |
| Travel time in seconds between origin and destination indices. |
| Indicates additional time in seconds spent waiting to reach the opening time in a given travel segment. Present if at least one window constraint is used. |
| The time spent active at a waypoint. Those are planned activities, such as loading, unloading, delivering the parcel, etc. |
| The estimated departure time for the route, or a single leg given at the
local time of the first waypoint. Specified as a |
| The estimated arrival time for the route, or a single leg given at the
local time of the last waypoint. Specified as a
|
Response codes
Code | Meaning & possible causes |
---|---|
200 | OK: Response returned. |
400 | Bad request:
|
404 | Not found: Request path is incorrect. |
429 | Too many requests: Too many requests were sent in a given amount of time for the supplied API Key. |
500 | Internal Server Error: The service cannot handle the request right now, an unexpected condition has occurred. |
503 | Service Unavailable: The service cannot handle the request right now, this is certainly a temporary state. |
Example
Request example
https://api.tomtom.com/routing/waypointoptimization/1?key={Your_API_Key}
POST request body
1{2 "waypoints": [3 {4 "point": {5 "latitude": 45.458546,6 "longitude": 9.150497 }8 },9 {10 "point": {11 "latitude": 50.033688,12 "longitude": 14.822613 }14 },15 {16 "point": {17 "latitude": 50.033688,18 "longitude": 14.53822619 }20 },21 {22 "point": {23 "latitude": 50.033688,24 "longitude": 13.53822625 }26 }27 ],28 "options": {29 "travelMode": "truck",30 "vehicleMaxSpeed": 11031 }32}
Response body
1{2 "optimizedOrder": [0, 2, 1, 3]3}