Skip to content
Documentation

Optimized route

Last updated

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, or send the JSON without spaces. The API does not decode + as a space and rejects the request as unparseable.

admin_crossingsoptional boolean
When true, the route summary includes 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).

Default:false

alternatesoptional integer
Number of alternative routes to return. Forced to 0 for more than 2 waypoints.

Default:0

banner_instructionsoptional boolean
Include OSRM-format banner instructions, if format = osrm.

Default:false

directions_typeoptional string

Default:instructions

Values
noneNo maneuvers or instructions.
maneuversManeuvers only, no narrative text.
instructionsManeuvers with narrative instructions (default).
elevation_intervaloptional number
Elevation sample interval in meters along the path. 0 = no elevation.

Default:0

linear_referencesoptional boolean
Include base64-encoded OpenLR references per edge in the response..

Default:false

locationsarray of objectsrequired
locations.date_timeoptional string
Per-location ISO 8601 datetime override, in the format YYYY-MM-DDTHH:MM, e.g. 2016-07-03T08:06.
locations.display_latoptional number
Latitude of the map location in degrees. If provided the 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.
locations.display_lonoptional number
Latitude of the map location in degrees. If provided the 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.
locations.headingoptional integer
Preferred approach heading in degrees.
locations.heading_toleranceoptional integer
How close in degrees a given street's angle must be in order for it to be considered as in the same direction of the heading parameter. The default value is service configuration dependent (60 by default).
locations.latnumberrequired
locations.lonnumberrequired
locations.minimum_reachabilityoptional integer
Minimum number of reachable edges for a snap candidate. The default and max values are service configuration dependent (50 and 100 by default, respectively).

Default:50

locations.nameoptional string
Label echoed in the response.
locations.node_snap_toleranceoptional number
Snap-to-node distance tolerance in meters. The default value is service dependent (5 by default).
locations.preferred_layeroptional integer
If set, edges whose layer does not match this value are discarded from candidate search. Note that this is a "soft" filter, meaning if no other candidates are found, Valhalla will fall back to including edges that did not match this filter.
locations.preferred_sideoptional string
Preferred side of road to snap to.

Default:eitherAllowed:same, opposite, eitherExample:opposite

locations.radiusoptional integer
Candidate search radius in meters: all viable edge candidates within the radius are correlated. If none are found, the best one outside the radius is correlated. The default is service dependent, and defaults to 0 (only the closest edge is considered as candidate). The max value is service configuration dependent (200 by default).
locations.rank_candidatesoptional boolean
Rank snap candidates by distance to input.

Default:true

locations.search_cutoffoptional integer
Hard cutoff for candidate search in meters. Default is service configuration dependent (35000 by default).
locations.search_filteroptional object
Optional filters to exclude candidate edges based on their attribution.
locations.streetoptional string
Street address hint for snapping.
locations.street_side_cutoffoptional string

Allowed:motorway, trunk, primary, secondary, tertiary, unclassified, residential, service_otherExample:primary

locations.street_side_max_distanceoptional integer
The max distance in meters that the input coordinates or display ll can be from the edge centerline for them to be used for determining the side of street. Beyond this distance the side of street is set to none. The default value is service configuration dependent (1000 by default).
locations.street_side_toleranceoptional integer
If your input coordinate is less than this tolerance away from the edge centerline then we set your side of street to none otherwise your side of street will be left or right depending on direction of travel. The default value is service configuration dependent (5 by default).
locations.typeoptional string
First and last location are always forced to break.

Default:breakExample:break

Values
breakStop here; starts or ends a route leg. Allows U-turns.
throughPass through without stopping. No U-turn; keeps direction of travel.
viaWaypoint with a maneuver instruction but no leg-break. Allows U-turns.
break_throughLike `break` but does not allow U-turns at the location.
locations.waitingoptional number
Waiting time in seconds at this stop (break/break_through only, not origin/destination).
prioritize_bidirectionaloptional boolean
Prefer bidirectional A* even when date_time.type={depart_at,arrive_by,current} in /route, or prefer CostMatrix over TDMatrix when calling /sources_to_targets

Default:false

recostingsoptional array of objects
Re-score the found path under additional named costings.
recostings.alley_penaltyoptional number
A penalty that is applied when transitioning onto an alley. Default is 60 seconds for bicycle, 5 seconds otherwise.
recostings.closure_factoroptional number
A factor that penalizes the cost when traversing a closed edge (eg: if 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.

Default:9

recostings.country_crossing_costoptional number
A cost applied when encountering an international border. This cost is added to the estimated and elapsed times.

Default:600

recostings.country_crossing_penaltyoptional number
A penalty applied for a country crossing. This penalty can be used to create paths that avoid spanning country boundaries.

Default:0

recostings.destination_only_penaltyoptional number
A penalty applied when entering an road which is only allowed to enter if necessary to reach the destination.

Default:600

recostings.disable_hierarchy_pruningoptional boolean
Disable graph hierarchy culling; if the bee-line distance between waypoints exceeds the config parameter value for service_limits.max_distance_disable_hierarchy_culling, the option is ignored

Default:false

recostings.ferry_costoptional number
A cost applied when entering a ferry. This cost is added to the estimated and elapsed times.

Default:300

recostings.fixed_speedoptional integer
Fixed speed the vehicle can go in km/h. Used to override the calculated speed. Can be useful if speed of vehicle is known. Value must be between 1 and 252. The default value is 0, which disables fixed speed and falls back to the standard calculated speed based on the road attribution.

Default:0

recostings.gate_costoptional number
A cost applied when a gate with undefined or private access is encountered. This cost is added to estimated and elapsed times.

Default:30

recostings.gate_penaltyoptional number
A penalty applied when a gate with no access information is on the road. Default is 300 for bicycle, 30 otherwise.
recostings.ignore_accessoptional boolean
Will ignore mode-specific access tags. Especially useful for matching GPS traces to the road network regardless of restrictions

Default:false

recostings.ignore_closuresoptional boolean
If set to 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.

Default:false

recostings.ignore_onewaysoptional boolean
If set to 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.

Default:false

recostings.ignore_restrictionsoptional boolean
If set to true, ignores any restrictions (e.g. turn/dimensional/conditional restrictions). Especially useful for matching GPS traces to the road network regardless of restrictions.
recostings.maneuver_penaltyoptional number
A penalty applied when transitioning between roads that do not have consistent naming — in other words, no road names in common. This penalty can be used to create simpler routes that tend to have fewer maneuvers or narrative guidance instructions. The default maneuver penalty is five seconds.

Default:5

recostings.nameoptional string
Required for recostings entries; must be unique.
recostings.private_access_penaltyoptional number
A penalty applied when a gate or bollard with access=private is encountered. Default is 600 for pedestrian, 450 otherwise.
recostings.rail_ferry_costoptional number
A cost applied when entering a rail ferry. This cost is added to the estimated and elapsed times.

Default:300

recostings.service_factoroptional number
A factor that modifies (multiplies) the cost when generic service roads are encountered.

Default:1

recostings.service_penaltyoptional number
A penalty applied for transition to generic service road. The default penalty is 0 for trucks and pedestrian, 75 for auto/bus/taxi, 15 otherwise.
recostings.shortestoptional boolean
Changes the metric to quasi-shortest, i.e. purely distance-based costing. Note, this will disable all other costings & penalties. Also note, shortest will not disable hierarchy pruning, leading to potentially sub-optimal routes for some costing models.

Default:false

recostings.speed_penalty_factoroptional number
Penalty factor applied for edges when edge speed is faster than top speed. The default value is 0.05. If you want to use top_speed without penalizing roads where the edge speed is much lower than top_speed, set this value to 0.

Default:0.05

recostings.speed_typesoptional array of strings
Which speed sources to consider for computing edge cost. Defaults to all available types. Predicted, current and freeflow additionally require 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.
Values
currentThe current live traffic speed
freeflowNighttime (7pm–7am) average speed stored on the edge
constrainedDaytime (7am–7pm) average speed stored on the edge
predictedHistorical per-edge speed profiles (5-min buckets over a week)
recostings.toll_booth_costoptional number
A cost applied when a toll booth is encountered. This cost is added to the estimated and elapsed times.

Default:15

recostings.toll_booth_penaltyoptional number
A penalty applied to the cost when a toll booth is encountered. This penalty can be used to create paths that avoid toll roads.

Default:0

recostings.use_ferryoptional number
This value indicates the willingness to take ferries. This is a range of values between 0 and 1. Values near 0 attempt to avoid ferries and values near 1 will favor ferries. Note that sometimes ferries are required to complete a route so values of 0 are not guaranteed to avoid ferries entirely.

Default:0.5

recostings.use_living_streetsoptional number
This value indicates the willingness to take living streets. This is a range of values between 0 and 1. Values near 0 attempt to avoid living streets and values near 1 will favor living streets. The default value is 0 for truck, 0.5 for bicycle, 0.6 for pedestrian, 0.1 otherwise. Note that sometimes living streets are required to complete a route so values of 0 are not guaranteed to avoid living streets entirely.
recostings.use_rail_ferryoptional number
This value indicates the willingness to take rail ferries. This is a range of values between 0 and 1. Values near 0 attempt to avoid rail ferries and values near 1 will favor them. Note that sometimes rail ferries may be required to complete a route so values of 0 are not guaranteed to avoid them entirely.

Default:0.4

recostings.use_tracksoptional number
This value indicates the willingness to take track roads. This is a range of values between 0 and 1. Values near 0 attempt to avoid tracks and values near 1 will favor tracks a little bit. The default value is 0 for auto and truck, 0.5 otherwise. Note that sometimes tracks are required to complete a route so values of 0 are not guaranteed to avoid tracks entirely.
recostings.exclude_bridgesoptional boolean
This value indicates whether or not the path may include bridges. If 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.

Default:false

recostings.exclude_ferriesoptional boolean
This value indicates whether or not the path may include ferries. If 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.

Default:false

recostings.exclude_highwaysoptional boolean
This value indicates whether or not the path may include highways. If 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.

Default:false

recostings.exclude_tollsoptional boolean
This value indicates whether or not the path may include tolls. If 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.

Default:false

recostings.exclude_tunnelsoptional boolean
This value indicates whether or not the path may include tunnels. If 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.

Default:false

roundabout_exitsoptional boolean
When true, exit instructions at roundabouts are added to the output.

Default:true

shape_formatoptional string
Not all formats are supported by all endpoints, e.g. no_shape is not valid for isochrone.

Default:polyline6Allowed:polyline6, polyline5, geojson, no_shapeExample:polyline6

turn_lanesoptional boolean
When true, each maneuver may include a lanes array describing lane-level guidance: possible directions and which lanes are valid or active for following the maneuver.

Default:false

voice_instructionsoptional boolean
Include OSRM-format voice instructions, if format = osrm.

Default:false

costingstringrequired
multimodal is not available. The street graph has no transit; use transit routing at /otp/plan.

Allowed:auto, bicycle, pedestrian, truck, bus, taxi, motor_scooter, motorcycle, bikeshare, auto_pedestrianExample:auto

costing_optionsoptional object
Costing options keyed by costing model name.
costing_options.autooptional object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
costing_options.bicycleoptional object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
costing_options.bikeshareoptional object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
costing_options.busoptional object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
costing_options.motor_scooteroptional object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
costing_options.motorcycleoptional object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
costing_options.pedestrianoptional object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
costing_options.taxioptional object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
costing_options.truckoptional object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
date_timeoptional object
date_time.typeoptional integer
0=current, 1=depart_at, 2=arrive_by, 3=invariant

Allowed:0, 1, 2, 3

date_time.valueoptional string
ISO 8601 local datetime string in the format YYYY-MM-DDTHH:MM, e.g. 2016-07-03T08:06. Required for types 1, 2, 3.
exclude_locationsoptional array of objects
A set of locations to exclude or avoid within a route.
exclude_locations.date_timeoptional string
Per-location ISO 8601 datetime override, in the format YYYY-MM-DDTHH:MM, e.g. 2016-07-03T08:06.
exclude_locations.display_latoptional number
Latitude of the map location in degrees. If provided the 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.
exclude_locations.display_lonoptional number
Latitude of the map location in degrees. If provided the 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.
exclude_locations.headingoptional integer
Preferred approach heading in degrees.
exclude_locations.heading_toleranceoptional integer
How close in degrees a given street's angle must be in order for it to be considered as in the same direction of the heading parameter. The default value is service configuration dependent (60 by default).
exclude_locations.latnumberrequired
exclude_locations.lonnumberrequired
exclude_locations.minimum_reachabilityoptional integer
Minimum number of reachable edges for a snap candidate. The default and max values are service configuration dependent (50 and 100 by default, respectively).

Default:50

exclude_locations.nameoptional string
Label echoed in the response.
exclude_locations.node_snap_toleranceoptional number
Snap-to-node distance tolerance in meters. The default value is service dependent (5 by default).
exclude_locations.preferred_layeroptional integer
If set, edges whose layer does not match this value are discarded from candidate search. Note that this is a "soft" filter, meaning if no other candidates are found, Valhalla will fall back to including edges that did not match this filter.
exclude_locations.preferred_sideoptional string
Preferred side of road to snap to.

Default:eitherAllowed:same, opposite, eitherExample:opposite

exclude_locations.radiusoptional integer
Candidate search radius in meters: all viable edge candidates within the radius are correlated. If none are found, the best one outside the radius is correlated. The default is service dependent, and defaults to 0 (only the closest edge is considered as candidate). The max value is service configuration dependent (200 by default).
exclude_locations.rank_candidatesoptional boolean
Rank snap candidates by distance to input.

Default:true

exclude_locations.search_cutoffoptional integer
Hard cutoff for candidate search in meters. Default is service configuration dependent (35000 by default).
exclude_locations.search_filteroptional object
Optional filters to exclude candidate edges based on their attribution.
exclude_locations.streetoptional string
Street address hint for snapping.
exclude_locations.street_side_cutoffoptional string

Allowed:motorway, trunk, primary, secondary, tertiary, unclassified, residential, service_otherExample:primary

exclude_locations.street_side_max_distanceoptional integer
The max distance in meters that the input coordinates or display ll can be from the edge centerline for them to be used for determining the side of street. Beyond this distance the side of street is set to none. The default value is service configuration dependent (1000 by default).
exclude_locations.street_side_toleranceoptional integer
If your input coordinate is less than this tolerance away from the edge centerline then we set your side of street to none otherwise your side of street will be left or right depending on direction of travel. The default value is service configuration dependent (5 by default).
exclude_locations.typeoptional string
First and last location are always forced to break.

Default:breakExample:break

Values
breakStop here; starts or ends a route leg. Allows U-turns.
throughPass through without stopping. No U-turn; keeps direction of travel.
viaWaypoint with a maneuver instruction but no leg-break. Allows U-turns.
break_throughLike `break` but does not allow U-turns at the location.
exclude_locations.waitingoptional number
Waiting time in seconds at this stop (break/break_through only, not origin/destination).
exclude_polygonsoptional array or object
Array of coordinate rings [[lon,lat],…] or a GeoJSON FeatureCollection. Roads intersecting these rings will be avoided during path finding. Takes one of the 2 forms listed below.
array of arraysarray of arrays
Array of closed coordinate rings. All edges intersecting any ring are excluded.
objectobject
GeoJSON FeatureCollection. Each Feature may carry a properties.levels array to restrict exclusion to specific building/indoor levels in pedestrian routing.
formatoptional string
Not all formats are supported by all endpoints, e.g. geotiff is isochrone-only.

Default:jsonAllowed:json, gpx, osrm, pbf, geotiff, mvtExample:json

idoptional string
Arbitrary request identifier echoed in the response.
languageoptional string
BCP47 locale for narrative output. See locales/ for supported values.

Default:en-US

linear_cost_factorsoptional array of objects
Customized cost factors that influence path finding, specified as an array of JSON objects. Objects can be either a GeoJSON linestring feature and a "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.
object with shape, factorobject
object with type, geometry, propertiesobject
unitsoptional string

Default:kmAllowed:km, miles, mi

Response

tripobject
A route through the network, split into legs between the requested locations.
trip.languagestring
Language tag the narrative instructions are written in.

Example:en-US

trip.legsarray of objects
One leg per consecutive pair of break locations.
trip.locationsarray of objects
The requested locations, snapped to the network and in the order visited.
trip.statusinteger
Zero on success.

Example:0

trip.status_messagestring
Human-readable form of status.

Example:Found route between points

trip.summaryobject
Totals for a trip or a single leg.
trip.unitsstring
Units the lengths in this trip are expressed in.

Allowed:kilometers, miles

trip.warningsarray of objects
Non-fatal notes about the request, such as a parameter that was ignored. Absent when there are none.

See the Routing Platform overview for API access, travel modes, and the machine-readable schema.

Reference: Valhalla optimized route API reference