Calculate Route
Purpose
The Calculate Route service calculates a route between an origin and a destination, passing through waypoints if they are specified.
- The route will take into account factors such as current traffic and the typical road speeds on the requested day of the week and time of day.
- Information returned includes the distance, estimated travel duration, and a representation of the route geometry.
Run this endpoint
You can easily run this endpoint. Go to the TomTom Routing API Playground page and follow the directions.
Request data
HTTPS method: POST
Constants and parameters enclosed in curly brackets { } must be replaced with their values.
Generic request format
https://{baseURL}/maps/orbis/routing/routes/calculate?apiVersion={integer}POST URL example
https://api.tomtom.com/maps/orbis/routing/routes/calculate?apiVersion=3POST curl command example
curl -X POST "https://api.tomtom.com/maps/orbis/routing/routes/calculate" -H "Content-Type:application/json" -H "TomTom-Api-Version:3" -H "TomTom-Api-Key:{Your_API_Key}" -H "Attributes:routes" -d \'{ "routePlanningLocations": { "origin": { "type": "Point", "coordinates": [13.42936, 52.50931] }, "destination": { "type": "Point", "coordinates": [13.43872, 52.50274] } }, "vehicleEngineType": "electric", "path": { "type": "LineString", "coordinates": [ [13.42936, 52.5093], [13.42859, 52.50844] ] }, "routeType": "short"}'POST curl command example with entry points
curl -X POST "https://api.tomtom.com/maps/orbis/routing/routes/calculate" -H "Content-Type:application/json" -H "TomTom-Api-Version:3" -H "TomTom-Api-Key:{Your_API_Key}" -H "Attributes:routes" -d \'{ "routePlanningLocations": { "origin": { "type": "Point", "coordinates": [13.626480, 52.328416] }, "destination": { "type": "Point", "coordinates": [13.508614, 52.36428] } }, "legs" : [ { "routeStop": { "entryPoints": { "type": "MultiPoint", "coordinates": [ [13.50929, 52.36443], [13.51781, 52.38909], [13.52149, 52.37038], [13.51031, 52.36281] ] } } } ]}'Types
The following data table describes the types that can be used in the Calculate Route service.
Type | Description |
|---|---|
| Latitude, longitude pair (in EPSG:4326 projection), with the following constraints:
Example: |
| A |
| A date and time specified in RFC 3339 format with an optional time zone offset. Examples:
|
Avoids parameter possible values
Value | Description |
|---|---|
tollRoads | Avoids toll roads. |
motorways | Avoids motorways. Note: Avoiding motorways for long routes of approximately 500km+ may result in computation timeouts of the primary route or path alternatives. |
ferries | Avoids ferries. |
unpavedRoads | Avoids unpaved roads. |
carpools | Avoids routes that require use of carpool (HOV/High Occupancy Vehicle) lanes. |
alreadyUsedRoads | Avoids using the same road multiple times. |
borderCrossings | Avoids crossing country borders. |
tunnels | Avoids tunnels. |
carTrains | Avoids car trains. |
Request headers
The following data table describes supported HTTP request headers.
- Required headers must be used or the call will fail.
- Optional headers may be used.
- The order of request headers is not important.
Required headers | Description |
|---|---|
| TomTom-Api-Key | Authorization key to access the API.
Value: Your valid |
| Attributes | Specifies which response fields to include using dot-notation. Fields marked as EXPLICIT in the response documentation must be explicitly listed in this header to be included in the response. See the Response field selection section for details and examples. |
| Content-Type | Specifies the MIME type of the body of the request.
Value: |
Optional headers | Description |
|---|---|
| TomTom-Api-Version | Specifies API version Note: this header is required if the query parameter |
| Accept | Specifies the MIME type of the body of the response. |
| Accept-Encoding | Requests that the response be compressed.
Value: |
| Content-Encoding | Specifies the compression used for the request body. Currently, only
Note: This header is optional. Values:
|
| Tracking-ID | Specifies an identifier for the request.
|
| Attributes-Exclude | Specifies which response fields to exclude using dot-notation. The exclusion is applied after the inclusion list and overrides it. See the Response field selection section for details and examples. |
| Accept-Language | Determines the language of the returned names of places and phonetic translations in guidance.
If the selected language isn’t supported, |
Base path parameters
The following table describes the parameters that can be used in the Calculate Route service.
- Required parameters must be used or the call will fail.
- The order of the required parameters is important and must be followed.
- There are no optional parameters.
Required parameters (Base path) | Description |
|---|---|
| Base URL for calling the API. |
Request parameters
The following table describes the parameters that can be used in the Calculate Route service.
- Required parameters must be used or the call will fail.
- Optional parameters may be used.
- The order of the optional request parameters is not important.
Required parameters | Description |
|---|---|
| Specifies the API version. Note: This parameter is not required if the header |
POST data parameters
The path field, which represents a polyline using GeoJSON format, is used to reconstruct a route.
This route is then used as a reference route for route reassessment, or calculating zero or more alternative routes.
- There are two options how to pass these polyline representations: for the entire route or per leg.
- The provided polyline is used as input for route reconstruction.
- The origin and destination points are expected to be at (or very near) the beginning and end of the reference route, respectively.
The following tables describe the required and optional POST data parameters, respectively:
Required parameters | Description |
|---|---|
| Locations through which the route is calculated. |
Optional parameters | Description |
|---|---|
| The date and time of departure from the origin point.
Default value: |
| The date and time of arrival at the destination point.
The
Value: |
| Specifies something that the route calculation should try to avoid when
determining the route. It can contain one or more possible values
listed under Avoids parameter possible values and provided as an array of strings. If specified, the array must not be empty.
Avoid values are applied to all route legs. Must not be used together with per-leg |
avoidAreasobject | Defines areas of certain shapes that should be avoided when planning routes. Supported shapes include |
rectanglesarray | This is an array of GeoJSON Feature objects with a maximum of ten elements. Each object describes an axis-aligned rectangle.
|
typestring | Must have the value |
bboxarray | Represents the area of the rectangle to be avoided. The array must contain exactly 4 numbers. |
| Must be null. |
| Locations to be used as input for route reconstruction.
For more information on representing route geometry formats, see the GeoJSON format section. |
| An array of objects with the parameters for the computation of each leg. If the parameter is such
that it is available for use in the query parameters, then its simultaneous use in the query
parameters and in the POST data is prohibited, and such a request will be returned with an error.
|
| The directional heading of the vehicle, in degrees starting at true North and continuing in a clockwise direction.
Maximum value: |
| Specifies that the route calculation should try to avoid ETC-transponder-only toll roads when determining the route if a vehicle does not have an ETC transponder. Possible values are:
Default value: |
| Maximum speed of the vehicle in kilometers/hour.
Default value: |
| Weight of the vehicle in kilograms. |
| Number of desired path alternative routes to be calculated. The value provided:
Default value: |
| Decides how traffic is considered for computing routes.
Default value: |
| Specifies the type of optimization used when calculating routes. Possible values are:
Default value: |
| Default value and only allowed value: |
| The engine type of the vehicle.
Default value: |
| Specifies the preference of roadside on arrival to waypoints and destination. Stop on the road has to be set at least two meters to the preferred side,
otherwise the behavior will default to
Default value: |
RoutePlanningLocations
Parameters | Description |
|---|---|
originA GeoJSON object of type | Origin location for the route calculation.
For more information, see the GeoJSON format section. |
waypointsA GeoJSON object of type | Optional, intermediate waypoint locations for the route calculation.
For more information, see the GeoJSON format section. |
destinationA GeoJSON object of type | Destination location for the route calculation.
For more information, see the GeoJSON format section. |
RouteStop
Optional parameters | Description |
|---|---|
pauseDurationInSecondsinteger | Specifies the waiting duration at route stops.
It must be 0 in the last leg (the destination). |
entryPointsGeoJSON MultiPoint object | Specifies the entry points for the stop at the end of the current leg in GeoJSON MultiPoint format. The route to the stop is calculated based on these entry points.
For more details about GeoJSON, refer to the RFC 7946 . |
Route avoid
The route calculation will try to avoid the specified road attribute for the leg that contains it.
Parameters | Description |
|---|---|
| Specifies the name of the road attribute to configure. |
entryPoints (GeoJSON MultiPoint)
The entryPoints field uses the GeoJSON MultiPoint format. Each coordinate is specified as [longitude, latitude].
Example:
{ "type": "MultiPoint", "coordinates": [ [13.50929, 52.36443], [13.51781, 52.38909] ]}Request content example
Note: for the purpose of brevity the following example may contain fields that are incompatible with others, and in practice only a subset of them will be present in the request.
{ "avoidAreas": { "rectangles": [ { "type": "Feature", "bbox": [2.26593, 48.81851, 2.41115, 48.90309], "geometry": null } ] }, "avoids": ["motorways", "ferries"], "path": { "type": "LineString", "coordinates": [ [ 13.42936, 52.50930 ], [ 13.42859, 52.50844 ], [ 13.42742, 52.50601 ] ] }, "legs": [ { "routeType": "efficient", "routeStop": { "pauseDurationInSeconds": 610, "entryPoints": { "type": "MultiPoint", "coordinates": [ [ 13.42742, 52.50601 ] ] } }, "avoids": [ { "name": "tollRoads" } ] }, { "path": { "type": "LineString", "coordinates": [ [ 13.42936, 52.5093 ], [ 13.42859, 52.50844 ], [ 13.42859, 52.50844 ] ] } }, { "routeType": "short" } ], "vehicleHeadingInDegrees": 150, "vehicleHasElectronicTollCollectionTransponder": "all", "vehicleMaxSpeedInKilometersPerHour": 120, "vehicleWeightInKilograms": 2000, "traffic": "live"}Response field selection
The response field selection mechanism allows you to control which fields are included in or excluded from the API response.
This is done through the required Attributes HTTP request header and the optional Attributes-Exclude header.
The Attributes header
The Attributes header is required and specifies which response fields to include using a dot-notation format.
Rules:
- Any field listed in the
Attributesheader, including its sub-tree, will be included in the response if applicable. - Fields marked as EXPLICIT (indicated by EXPLICIT in the response field documentation below) must be explicitly listed in this header to be returned. They are never included implicitly by specifying a parent field or by using a wildcard (
*). - The wildcard
*can be used at deeper levels to include all non-EXPLICIT children of a field, but cannot be used as the only top-level value.
Syntax:
The value uses a listed dot-notation format:
Attributes: routes.summary, routes.legsAttributes: routes(summary, legs)Attributes: routes(*, someExplicitField)The (...) notation can be used to group fields under a common parent and avoid repetition.
The (*, ...) notation includes all non-EXPLICIT children plus the listed EXPLICIT fields.
Examples:
Attributes: routes -- includes all non-EXPLICIT fields under routesAttributes: routes, routes.someExplicitField -- includes routes and an EXPLICIT fieldAttributes: routes(*, someExplicitField) -- same as above using grouping notationAttributes: routes(summary, legs.summary) -- includes only the specified fields The Attributes-Exclude header
The Attributes-Exclude header specifies which response fields to exclude using the same dot-notation format.
Rules:
- Any field listed in the
Attributes-Excludeheader, including its entire sub-tree, will be omitted from the response. - The exclusion is applied after the inclusion list and overrides it.
- The wildcard
*is not allowed in the exclusion list.
Example:
Attributes: routesAttributes-Exclude: routes.legs.path -- include everything except the path geometryEXPLICIT response fields
Some response fields are marked as EXPLICIT and must be explicitly requested in the Attributes header.
They are not included by default, even when their parent field is requested.
This mechanism avoids unexpected increases in response size and computation cost.
This endpoint does not have any EXPLICIT response fields in this documentation.
Response data
Response headers
The following table describes the possible HTTP response headers.
Header | Description |
|---|---|
| Access-Control-Expose-Headers | The service whitelists response headers that browsers are allowed to
access. |
| Access-Control-Allow-Origin | The service allows cross-origin resource sharing. |
| Content-Encoding | The service supports HTTP compression if requested by the client. |
| Content-Language | The language used when assembling the response, for example, selecting localized place names, phonetic translations, or other language‑dependent fields. |
| Content-Type | The format of the response. |
| Cache-Control | The Cache-Control general-header field is used to specify directives
that must be obeyed by all caching mechanisms along the request/response
chain. It is supported by HTTP/1.1 clients. It may not be supported by
HTTP/1.0 clients.
|
| Tracking-ID | This is an identifier for the request. If |
Response codes
The following table describes the possible HTTP response codes.
Code | Meaning & possible causes |
|---|---|
200 | OK: A route or range was calculated and the body of the response contains the data for a successful response. |
400 | Bad request: One or more parameters were:
|
403 | Permission or authentication issues:
|
404 | Not Found: The requested resource could not be found, but it may be available again in the future. |
405 | Method Not Allowed: The client used an HTTP method other than POST. |
408 | Request timeout: The client took too long to transmit the request. |
414 | Requested uri is too long. |
415 | Unsupported Media Type. |
429 | Too Many Requests: Too many requests were sent in a given amount of time for the supplied API Key. |
500 | An error occurred while processing the request. Please try again later. This can also indicate that the request reached an internal computation time threshold and timed out. |
502 | Internal network connectivity issue. |
503 | Service currently unavailable. |
504 | Internal network connectivity issue. |
596 | Service not found. |
Example of a successful response
The routes in a successful response are listed in the order of decreasing optimality. In case the request includes the path field, the response will specify the reconstructed route before any alternative routes.
Note: for the purpose of brevity the following example contains all the fields described in this document. In practice some fields are incompatible with others, and only a subset of them will be present in the response depending on the given request parameters.
A response could look like this: (Note: Comments are contained within ... ....)
Response body - JSON
{ "routes": [ { "summary": { "lengthInMeters": 1147, "travelDurationInSeconds": 161, "trafficDelayDurationInSeconds": 15, "trafficLengthInMeters": 147, "departureDateTime": "2015-04-02T15:01:57+02:00", "arrivalDateTime": "2015-04-02T15:04:38+02:00" }, "legs": [ { "summary": { "lengthInMeters": 108, "travelDurationInSeconds": 11, "trafficDelayDurationInSeconds": 0, "trafficLengthInMeters": 0, "departureDateTime": "2015-04-02T15:01:57+02:00", "arrivalDateTime": "2015-04-02T15:02:07+02:00", "originalWaypointIndexAtEndOfLeg": 0, "entryPointIndexAtEndOfLeg": 0 }, "path": { "type": "LineString", "coordinates": [ [13.4293737, 52.5093087], [13.4291258, 52.5090373], ...further coordinates... ] }, }, ...further legs... ], "progressPoints": [ { "pathIndex": 0, "travelDurationInSeconds": 0, "distanceInMeters": 0 }, { "pathIndex": 5, "travelDurationInSeconds": 7, "distanceInMeters": 74 }, ...further progress points... { "pathIndex": 87, "travelDurationInSeconds": 161, "distanceInMeters": 1147 } ], "sections": { "travelMode": [ { "startPathIndex": 0, "endPathIndex": 3, "travelMode": "other" }, { "startPathIndex": 3, "endPathIndex": 7, "travelMode": "car" } ], "toll": [ { "startPathIndex": 2, "endPathIndex": 5 } ], "tunnel": [ { "startPathIndex": 3, "endPathIndex": 4 } ], "pedestrian": [ { "startPathIndex": 0, "endPathIndex": 1 } ], "traffic": [ { "startPathIndex": 3, "endPathIndex": 4, "iconCategory": "jam", "effectiveSpeedInKilometersPerHour": 40, "delayDurationInSeconds": 158, "delayMagnitude": "minor", "tec": { "effectCode": 4, "causes": [ { "mainCauseCode": 1 }, { "mainCauseCode": 26, "subCauseCode": 2 } ] } } ] ...further sections... } } ...further routes... ]}Example of an error response
If an error occurs, the response contains the description of the error. The error response would look like this:
{ "detailedError": { "code": <error code>, "message": "Error message" }}Structure of a successful response
Note that some names are implicitly defined. One example is the name leg
when describing legs as an array of leg objects.
JSON field | Description |
|---|---|
| The request may return more than one route. |
| The summary of a route, or of a route leg. |
| A description of a part of a route, comprised of an array of points.
|
| The route geometry in GeoJSON format. Contains a Example: |
| This object is available inside
|
| Index of the first coordinate (offset |
| Index of the last coordinate (offset |
| A 2-character ISO 3166-1 alpha-2 country code. |
| Type of the incident.
|
| The effective speed of the incident in km/h, averaged over its entire length. |
| The delay duration in seconds caused by the incident. |
| The magnitude of delay caused by the incident.
These values correspond to the values of the response field
|
| Details of the traffic event. It uses the definitions in the
TPEG2-TEC
standard. It can contain the |
| The effect on the traffic flow. Contains a value in the
|
| Each object in the array describes one cause of the traffic event.
|
| The main cause of the traffic event. Contains a value in the
|
| The sub-cause of the traffic event. Contains a value in the sub cause
table defined by the |
| A unique ID of the traffic incident. |
| The route or leg length in meters. |
| The estimated travel duration in seconds depending on
|
| The delay duration in seconds compared to free-flow conditions according to
real-time traffic information.
Note that this is zero if |
| The portion of the route or leg, expressed in meters, that is affected by traffic events which cause the delay. |
| The distance (in meters) from the origin point of the request to the first point where this route forks off from the reference route.
|
| The travel duration (in seconds) from the origin point of the request to the first point where this route forks off from the reference route.
|
| The coordinates of the first point following the origin point of the request where this route forks off from the reference route. The value is in GeoJSON format.
Example: For more details, see the GeoJSON format for deviation points section. |
| The estimated departure date and time for the route or leg. Specified as a
|
| The estimated arrival date and time for the route or leg. Specified as a
|
|
A
|
| The index of the waypoint at the end of the leg. |
| Identifies the entry point that was used for the route at the end of the leg. |
Structure of the section object
Each section object contains additional information about parts of a route. A section object contains at least the fields startPathIndex and endPathIndex. The section type is indicated by the key under which the array of section objects appears in the sections map.
JSON field | Description |
|---|---|
sections map key | The key in the
|
| This field is either set to the value given to the POST data parameter
|
Structure of an error response
JSON field | Description | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
detailedErrorobject | This object provides a representation of the error message. It contains
a
|
GeoJSON format
GeoJSON is a format for encoding geographic data using JSON, representing features and attributes.
Structure of GeoJSON object
A GeoJSON object includes:
Type: Specifies the object type, e.g. LineString, Point, etc.
Coordinates: Geographic coordinates in arrays, varying by geometry type, for example:
- Point: [longitude, latitude].
- LineString: Array of coordinate pairs, in format
[longitude, latitude].
For more details, refer to the RFC 7946
GeoJSON format for deviation points
Fields such as deviationPoint in the response are represented as GeoJSON objects. For these cases, the object will have:
"type": "Point""coordinates": an array containing a single[longitude, latitude]pair.
Example:
{ "type": "Point", "coordinates": [13.42936, 52.50930]}For more details, refer to the RFC 7946