Optimized route
Available on the following API tiers:
Plan a route visiting several locations in the most efficient order, solving the traveling salesman problem. The request is the same as street routing; the service chooses the order of the locations.
GETPOSThttps://transit.land/api/v2/routing/valhalla/optimized_route
Calculate a route visiting multiple locations in the most efficient order, solving the traveling salesman problem.
Request
The request object, url-encoded. Identical to the POST body. Encode spaces as %20 rather than +, or send the JSON without spaces; a + is not decoded as a space here and the request will be rejected as unparseable.
admins (array of administrative regions the route passes through) and admin_crossings (array of objects with from_admin_index, to_admin_index, from_shape_index, and to_shape_index indicating where and along which edge an administrative boundary is crossed).
YYYY-MM-DDTHH:MM, e.g. 2016-07-03T08:06.lat and lon parameters will be treated as the routing location and the display_lat and display_lon will be used to determine the side of street. Both display_lat and display_lon must be provided and valid to achieve the desired effect.
lat and lon parameters will be treated as the routing location and the display_lat and display_lon will be used to determine the side of street. Both display_lat and display_lon must be provided and valid to achieve the desired effect.
heading parameter. The default value is service configuration dependent (60 by default).
Exampleopposite
Exampleprimary
break.Examplebreak
YYYY-MM-DDTHH:MM, e.g. 2016-07-03T08:06.lat and lon parameters will be treated as the routing location and the display_lat and display_lon will be used to determine the side of street. Both display_lat and display_lon must be provided and valid to achieve the desired effect.
lat and lon parameters will be treated as the routing location and the display_lat and display_lon will be used to determine the side of street. Both display_lat and display_lon must be provided and valid to achieve the desired effect.
heading parameter. The default value is service configuration dependent (60 by default).
Exampleopposite
Exampleprimary
break.Examplebreak
search_filter.exclude_closures is false for origin and/or destination location and the route starts/ends on closed edges). Its value can range from 1.0 - don't penalize closed edges, to 10.0 - apply high cost penalty to closed edges. Default value is 9.0. Note: This factor is applicable only for motorized modes of transport, i.e auto, motorcycle, motor_scooter, bus, truck & taxi.
true, ignores all closures, marked due to live traffic closures, during routing. Note: This option cannot be set if location.search_filter.exclude_closures is also specified in the request and will return an error if it is.
true, ignores one-way restrictions. Especially useful for matching GPS traces to the road network ignoring uni-directional traffic rules. Not included in ignore_restrictions option.
true, ignores any restrictions (e.g. turn/dimensional/conditional restrictions). Especially useful for matching GPS traces to the road network regardless of restrictions.
shortest will not disable hierarchy pruning, leading to potentially sub-optimal routes for some costing models.
top_speed without penalizing roads where the edge speed is much lower than top_speed, set this value to 0.
date_time to be set. If the array is left empty, or none of these sources are available, Valhalla will fall back to the default speed.
exclude_bridges is set to true it is allowed to start and end with bridges, but is not allowed to have them in the middle of the route path, otherwise they are allowed. If set to true, it is highly plausible that no path will be found.
exclude_ferries is set to true it is allowed to start and end with ferries, but is not allowed to have them in the middle of the route path, otherwise they are allowed. If set to true, it is highly plausible that no path will be found.
exclude_highways is set to true it is allowed to start and end with highways, but is not allowed to have them in the middle of the route path, otherwise they are allowed. If set to true, it is highly plausible that no path will be found.
exclude_tolls is set to true it is allowed to start and end with tolls, but is not allowed to have them in the middle of the route path, otherwise they are allowed. If set to true, it is highly plausible that no path will be found.
exclude_tunnels is set to true it is allowed to start and end with tunnels, but is not allowed to have them in the middle of the route path, otherwise they are allowed. If set to true, it is highly plausible that no path will be found.
search_filter.exclude_closures is false for origin and/or destination location and the route starts/ends on closed edges). Its value can range from 1.0 - don't penalize closed edges, to 10.0 - apply high cost penalty to closed edges. Default value is 9.0. Note: This factor is applicable only for motorized modes of transport, i.e auto, motorcycle, motor_scooter, bus, truck & taxi.
true, ignores all closures, marked due to live traffic closures, during routing. Note: This option cannot be set if location.search_filter.exclude_closures is also specified in the request and will return an error if it is.
true, ignores one-way restrictions. Especially useful for matching GPS traces to the road network ignoring uni-directional traffic rules. Not included in ignore_restrictions option.
true, ignores any restrictions (e.g. turn/dimensional/conditional restrictions). Especially useful for matching GPS traces to the road network regardless of restrictions.
shortest will not disable hierarchy pruning, leading to potentially sub-optimal routes for some costing models.
top_speed without penalizing roads where the edge speed is much lower than top_speed, set this value to 0.
date_time to be set. If the array is left empty, or none of these sources are available, Valhalla will fall back to the default speed.
exclude_bridges is set to true it is allowed to start and end with bridges, but is not allowed to have them in the middle of the route path, otherwise they are allowed. If set to true, it is highly plausible that no path will be found.
exclude_ferries is set to true it is allowed to start and end with ferries, but is not allowed to have them in the middle of the route path, otherwise they are allowed. If set to true, it is highly plausible that no path will be found.
exclude_highways is set to true it is allowed to start and end with highways, but is not allowed to have them in the middle of the route path, otherwise they are allowed. If set to true, it is highly plausible that no path will be found.
exclude_tolls is set to true it is allowed to start and end with tolls, but is not allowed to have them in the middle of the route path, otherwise they are allowed. If set to true, it is highly plausible that no path will be found.
exclude_tunnels is set to true it is allowed to start and end with tunnels, but is not allowed to have them in the middle of the route path, otherwise they are allowed. If set to true, it is highly plausible that no path will be found.
no_shape is not valid for isochrone.Examplepolyline6
lanes array describing lane-level guidance: possible directions and which lanes are valid or active for following the maneuver.
Exampleauto
YYYY-MM-DDTHH:MM, e.g. 2016-07-03T08:06. Required for types 1, 2, 3.YYYY-MM-DDTHH:MM, e.g. 2016-07-03T08:06.lat and lon parameters will be treated as the routing location and the display_lat and display_lon will be used to determine the side of street. Both display_lat and display_lon must be provided and valid to achieve the desired effect.
lat and lon parameters will be treated as the routing location and the display_lat and display_lon will be used to determine the side of street. Both display_lat and display_lon must be provided and valid to achieve the desired effect.
heading parameter. The default value is service configuration dependent (60 by default).
Exampleopposite
Exampleprimary
break.Examplebreak
YYYY-MM-DDTHH:MM, e.g. 2016-07-03T08:06.lat and lon parameters will be treated as the routing location and the display_lat and display_lon will be used to determine the side of street. Both display_lat and display_lon must be provided and valid to achieve the desired effect.
lat and lon parameters will be treated as the routing location and the display_lat and display_lon will be used to determine the side of street. Both display_lat and display_lon must be provided and valid to achieve the desired effect.
heading parameter. The default value is service configuration dependent (60 by default).
Exampleopposite
Exampleprimary
break.Examplebreak
[[lon,lat],…] or a GeoJSON FeatureCollection. Roads intersecting these rings will be avoided during path finding. Takes one of the 2 forms listed below.properties.levels array to restrict exclusion to specific building/indoor levels in pedestrian routing.geotiff is isochrone-only.Examplejson
"factor" property or a plain object with a "shape" key, whose value needs to be an encoded polyline (with 6 digit precision), and a "factor" key whose value needs to be float. Valhalla will perform an edge walk (see the map matching documentation for more info) to match the geometry onto edges and use those factors in costing. Edges with factors larger than 1 will be increasingly avoided, while edges with factors smaller than 1 increasingly favored.
Example request
curl --get "https://transit.land/api/v2/routing/valhalla/optimized_route" \
-H "apikey: YOUR_API_KEY" \
--data-urlencode 'json={"costing":"auto","locations":[{"lat":37.7793,"lon":-122.4193},{"lat":37.7817,"lon":-122.4108},{"lat":37.7844,"lon":-122.4079}]}'Response
Exampleen-US
status.ExampleFound route between points
Example response
Show response
{
"trip": {
"language": "en-US",
"legs": [
{
"maneuvers": [
{
"bearing_after": 352,
"begin_shape_index": 0,
"cost": 22.899,
"end_shape_index": 8,
"instruction": "Drive north on US 101 North/Van Ness Avenue.",
"length": 0.207,
"street_names": [
"US 101 North",
"Van Ness Avenue"
],
"time": 20.747,
"travel_mode": "drive",
"travel_type": "car",
"type": 2,
"verbal_multi_cue": true,
"verbal_post_transition_instruction": "Continue for 200 meters.",
"verbal_pre_transition_instruction": "Drive north on U.S. 1 o1 North, Van Ness Avenue. Then, in 200 meters, Turn right onto Golden Gate Avenue.",
"verbal_succinct_transition_instruction": "Drive north. Then, in 200 meters, Turn right onto Golden Gate Avenue."
},
{
"bearing_after": 81,
"bearing_before": 351,
"begin_shape_index": 8,
"cost": 224.574,
"end_shape_index": 36,
"has_time_restrictions": true,
"instruction": "Turn right onto Golden Gate Avenue.",
"length": 0.845,
"street_names": [
"Golden Gate Avenue"
],
"time": 109.411,
"travel_mode": "drive",
"travel_type": "car",
"type": 10,
"verbal_post_transition_instruction": "Continue for 800 meters.",
"verbal_pre_transition_instruction": "Turn right onto Golden Gate Avenue.",
"verbal_succinct_transition_instruction": "Turn right.",
"verbal_transition_alert_instruction": "Turn right onto Golden Gate Avenue."
},
{
"bearing_before": 83,
"begin_shape_index": 36,
"cost": 0,
"end_shape_index": 36,
"instruction": "Your destination is on the right.",
"length": 0,
"time": 0,
"travel_mode": "drive",
"travel_type": "car",
"type": 5,
"verbal_pre_transition_instruction": "Your destination is on the right.",
"verbal_transition_alert_instruction": "Your destination will be on the right."
}
],
"shape": "{oz`gA|o|nhFwJjAuI\\}V~CiGjAuEx@cWzCeW|CyC\\SwCyIusAYaFYeEsAkS{GceAWuD_@sFkFiy@_Co^UmD_@{EsDuk@yDsl@UsD]_Fo@{IwEst@eBmXWyD]yEYoEi@sIEe@m@eJWaEsBo[i@wL",
"summary": {
"cost": 247.473,
"has_ferry": false,
"has_highway": false,
"has_time_restrictions": true,
"has_toll": false,
"length": 1.053,
"max_lat": 37.782246,
"max_lon": -122.410884,
"min_lat": 37.779214,
"min_lon": -122.420355,
"time": 130.158
}
},
{
"maneuvers": [
{
"bearing_after": 83,
"begin_shape_index": 0,
"cost": 26.928,
"end_shape_index": 11,
"instruction": "Drive east on Golden Gate Avenue.",
"length": 0.123,
"sign": {},
"street_names": [
"Golden Gate Avenue"
],
"time": 14.284,
"travel_mode": "drive",
"travel_type": "car",
"type": 2,
"verbal_multi_cue": true,
"verbal_post_transition_instruction": "Continue for 100 meters.",
"verbal_pre_transition_instruction": "Drive east on Golden Gate Avenue. Then, in 100 meters, Turn left onto Stevenson Street.",
"verbal_succinct_transition_instruction": "Drive east. Then, in 100 meters, Turn left onto Stevenson Street."
},
{
"bearing_after": 44,
"bearing_before": 134,
"begin_shape_index": 11,
"cost": 94.719,
"end_shape_index": 16,
"instruction": "Turn left onto Stevenson Street.",
"length": 0.277,
"street_names": [
"Stevenson Street"
],
"time": 40.655,
"travel_mode": "drive",
"travel_type": "car",
"type": 15,
"verbal_post_transition_instruction": "Continue for 300 meters.",
"verbal_pre_transition_instruction": "Turn left onto Stevenson Street.",
"verbal_succinct_transition_instruction": "Turn left.",
"verbal_transition_alert_instruction": "Turn left onto Stevenson Street."
},
{
"bearing_after": 316,
"bearing_before": 45,
"begin_shape_index": 16,
"cost": 55.415,
"end_shape_index": 24,
"instruction": "Turn left onto 5th Street.",
"length": 0.094,
"street_names": [
"5th Street"
],
"time": 15.95,
"travel_mode": "drive",
"travel_type": "car",
"type": 15,
"verbal_multi_cue": true,
"verbal_post_transition_instruction": "Continue for 90 meters.",
"verbal_pre_transition_instruction": "Turn left onto 5th Street. Then Your destination will be on the right.",
"verbal_succinct_transition_instruction": "Turn left. Then Your destination will be on the right.",
"verbal_transition_alert_instruction": "Turn left onto 5th Street."
},
{
"bearing_before": 315,
"begin_shape_index": 24,
"cost": 0,
"end_shape_index": 24,
"instruction": "Your destination is on the right.",
"length": 0,
"time": 0,
"travel_mode": "drive",
"travel_type": "car",
"type": 5,
"verbal_pre_transition_instruction": "Your destination is on the right.",
"verbal_transition_alert_instruction": "Your destination will be on the right."
}
],
"shape": "km`agAfwjnhFe@eKB_CXeCx@wFRiBFq@Pe@hB_HvOoTdCkDzAwBsBkC}LwPomAsaB}HmKoCuDaGxH}K|NwAjBqDzEWZW^wCjEeAvA",
"summary": {
"cost": 177.063,
"has_ferry": false,
"has_highway": false,
"has_time_restrictions": false,
"has_toll": false,
"length": 0.495,
"level_changes": [
[
18,
0
]
],
"max_lat": 37.784135,
"max_lon": -122.40748,
"min_lat": 37.781763,
"min_lon": -122.410884,
"time": 70.891
}
}
],
"locations": [
{
"lat": 37.7793,
"lon": -122.4193,
"original_index": 0,
"side_of_street": "right",
"type": "break"
},
{
"lat": 37.7817,
"lon": -122.4108,
"original_index": 1,
"side_of_street": "right",
"type": "break"
},
{
"lat": 37.7844,
"lon": -122.4079,
"original_index": 2,
"side_of_street": "right",
"type": "break"
}
],
"status": 0,
"status_message": "Found route between points",
"summary": {
"cost": 424.537,
"has_ferry": false,
"has_highway": false,
"has_time_restrictions": true,
"has_toll": false,
"length": 1.548,
"max_lat": 37.784135,
"max_lon": -122.40748,
"min_lat": 37.779214,
"min_lon": -122.420355,
"time": 201.05
},
"units": "kilometers"
}
}See the Routing Platform overview for API access, travel modes, and the machine-readable schema.
Reference: Valhalla optimized route API reference