Skip to content
Documentation

Map matching

Available on the following API tiers:

Transitland v2Beta

Snap a sequence of GPS coordinates to the road network and get back a route with turn-by-turn directions. To get road attributes along the matched path instead, use trace attributes.

POSThttps://transit.land/api/v2/routing/valhalla/trace_route

Match a sequence of coordinates to the road network and return the matched route with turn-by-turn directions.

Request

alternates
integer
Number of alternative matched routes to return.
Default0
begin_time
integer
Epoch start timestamp (seconds) for the trace. Used with durations to assign timestamps to encoded_polyline input.
directions_type
string
Defaultinstructions
Enumnonemaneuversinstructions
durations
array: number
Elapsed seconds between each successive pair of trace points. Used with begin_time to derive per-point timestamps from an encoded_polyline input.
linear_references
boolean
Include base64-encoded OpenLR location references for each matched graph edge.
Defaultfalse
trace_options
object
Fine-tuning parameters for the map-matching algorithm.
breakage_distance
number
Maximum gap in meters between trace points before starting a new segment.
gps_accuracy
number
GPS accuracy in meters associated with trace points.
interpolation_distance
number
Distance in meters beyond which trace points are merged together.
search_radius
number
Search radius in meters for road candidates per trace point.
turn_penalty_factor
number
Penalty for sharp turns. Increase (e.g. 500) to smooth pedestrian traces.
use_timestamps
boolean
When true, use per-point time values (or derived timestamps) for elapsed time calculation instead of internal costing.
Defaultfalse
elevation_interval
number
Elevation sample interval in meters along the matched path. 0 = disabled.
Default0
encoded_polyline
string
Polyline6-encoded trace shape. Mutually exclusive with shape.
shape
array: object
GPS trace points. Mutually exclusive with encoded_polyline.
date_time
string
Per-location ISO 8601 datetime override, in the format YYYY-MM-DDTHH:MM, e.g. 2016-07-03T08:06.
display_lat
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.
display_lon
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.
heading
integer
Preferred approach heading in degrees.
heading_tolerance
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).
lat
number
Required
lon
number
Required
minimum_reachability
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).
Default50
name
string
Label echoed in the response.
node_snap_tolerance
number
Snap-to-node distance tolerance in meters. The default value is service dependent (5 by default).
preferred_layer
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.
preferred_side
string
Preferred side of road to snap to.
Defaulteither
Enumsameoppositeeither

Exampleopposite

radius
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).
rank_candidates
boolean
Rank snap candidates by distance to input.
Defaulttrue
search_cutoff
integer
Hard cutoff for candidate search in meters. Default is service configuration dependent (35000 by default).
search_filter
object
Optional filters to exclude candidate edges based on their attribution.
street
string
Street address hint for snapping.
street_side_cutoff
string
Enummotorwaytrunkprimarysecondarytertiaryunclassifiedresidentialservice_other

Exampleprimary

street_side_max_distance
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).
street_side_tolerance
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).
type
string
First and last location are always forced to break.
Defaultbreak
Enumbreakthroughviabreak_through

Examplebreak

waiting
number
Waiting time in seconds at this stop (break/break_through only, not origin/destination).
date_time
string
Per-location ISO 8601 datetime override, in the format YYYY-MM-DDTHH:MM, e.g. 2016-07-03T08:06.
display_lat
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.
display_lon
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.
heading
integer
Preferred approach heading in degrees.
heading_tolerance
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).
lat
number
Required
lon
number
Required
minimum_reachability
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).
Default50
name
string
Label echoed in the response.
node_snap_tolerance
number
Snap-to-node distance tolerance in meters. The default value is service dependent (5 by default).
preferred_layer
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.
preferred_side
string
Preferred side of road to snap to.
Defaulteither
Enumsameoppositeeither

Exampleopposite

radius
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).
rank_candidates
boolean
Rank snap candidates by distance to input.
Defaulttrue
search_cutoff
integer
Hard cutoff for candidate search in meters. Default is service configuration dependent (35000 by default).
search_filter
object
Optional filters to exclude candidate edges based on their attribution.
street
string
Street address hint for snapping.
street_side_cutoff
string
Enummotorwaytrunkprimarysecondarytertiaryunclassifiedresidentialservice_other

Exampleprimary

street_side_max_distance
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).
street_side_tolerance
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).
type
string
First and last location are always forced to break.
Defaultbreak
Enumbreakthroughviabreak_through

Examplebreak

waiting
number
Waiting time in seconds at this stop (break/break_through only, not origin/destination).
shape_format
string
Not all formats are supported by all endpoints, e.g. no_shape is not valid for isochrone.
Defaultpolyline6
Enumpolyline6polyline5geojsonno_shape

Examplepolyline6

shape_match
string
Defaultwalk_or_snap
Enummap_snapedge_walkwalk_or_snap

Examplewalk_or_snap

costing
string
Not available here: multimodal — transit routing is served by the Transitland Routing API at /otp/plan, not by this engine.
Required
Enumautobicyclepedestriantruckbustaximotor_scootermotorcyclebikeshareauto_pedestrian

Exampleauto

costing_options
object
Costing options keyed by costing model name.
auto
object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
bicycle
object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
bikeshare
object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
bus
object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
motor_scooter
object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
motorcycle
object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
pedestrian
object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
taxi
object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
truck
object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
date_time
object
type
integer
0=current, 1=depart_at, 2=arrive_by, 3=invariant
Enum0123
value
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_locations
array: object
A set of locations to exclude or avoid within a route.
date_time
string
Per-location ISO 8601 datetime override, in the format YYYY-MM-DDTHH:MM, e.g. 2016-07-03T08:06.
display_lat
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.
display_lon
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.
heading
integer
Preferred approach heading in degrees.
heading_tolerance
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).
lat
number
Required
lon
number
Required
minimum_reachability
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).
Default50
name
string
Label echoed in the response.
node_snap_tolerance
number
Snap-to-node distance tolerance in meters. The default value is service dependent (5 by default).
preferred_layer
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.
preferred_side
string
Preferred side of road to snap to.
Defaulteither
Enumsameoppositeeither

Exampleopposite

radius
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).
rank_candidates
boolean
Rank snap candidates by distance to input.
Defaulttrue
search_cutoff
integer
Hard cutoff for candidate search in meters. Default is service configuration dependent (35000 by default).
search_filter
object
Optional filters to exclude candidate edges based on their attribution.
street
string
Street address hint for snapping.
street_side_cutoff
string
Enummotorwaytrunkprimarysecondarytertiaryunclassifiedresidentialservice_other

Exampleprimary

street_side_max_distance
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).
street_side_tolerance
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).
type
string
First and last location are always forced to break.
Defaultbreak
Enumbreakthroughviabreak_through

Examplebreak

waiting
number
Waiting time in seconds at this stop (break/break_through only, not origin/destination).
date_time
string
Per-location ISO 8601 datetime override, in the format YYYY-MM-DDTHH:MM, e.g. 2016-07-03T08:06.
display_lat
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.
display_lon
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.
heading
integer
Preferred approach heading in degrees.
heading_tolerance
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).
lat
number
Required
lon
number
Required
minimum_reachability
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).
Default50
name
string
Label echoed in the response.
node_snap_tolerance
number
Snap-to-node distance tolerance in meters. The default value is service dependent (5 by default).
preferred_layer
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.
preferred_side
string
Preferred side of road to snap to.
Defaulteither
Enumsameoppositeeither

Exampleopposite

radius
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).
rank_candidates
boolean
Rank snap candidates by distance to input.
Defaulttrue
search_cutoff
integer
Hard cutoff for candidate search in meters. Default is service configuration dependent (35000 by default).
search_filter
object
Optional filters to exclude candidate edges based on their attribution.
street
string
Street address hint for snapping.
street_side_cutoff
string
Enummotorwaytrunkprimarysecondarytertiaryunclassifiedresidentialservice_other

Exampleprimary

street_side_max_distance
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).
street_side_tolerance
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).
type
string
First and last location are always forced to break.
Defaultbreak
Enumbreakthroughviabreak_through

Examplebreak

waiting
number
Waiting time in seconds at this stop (break/break_through only, not origin/destination).
exclude_polygons
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.
option 1
array: array
Array of closed coordinate rings. All edges intersecting any ring are excluded.
option 2
object
GeoJSON FeatureCollection. Each Feature may carry a properties.levels array to restrict exclusion to specific building/indoor levels in pedestrian routing.
format
string
Not all formats are supported by all endpoints, e.g. geotiff is isochrone-only.
Defaultjson
Enumjsongpxosrmpbfgeotiffmvt

Examplejson

id
string
Arbitrary request identifier echoed in the response.
language
string
BCP47 locale for narrative output. See locales/ for supported values.
Defaulten-US
linear_cost_factors
array: object
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.
option 1
object
option 2
object
option 1
object
option 2
object
units
string
Defaultkm
Enumkmmilesmi

Example request

curl -X POST "https://transit.land/api/v2/routing/valhalla/trace_route" \
  -H "apikey: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"costing":"auto","shape":[{"lat":37.7891,"lon":-122.4011},{"lat":37.7887,"lon":-122.4016},{"lat":37.7883,"lon":-122.4022},{"lat":37.7879,"lon":-122.4028}],"shape_match":"map_snap"}'

Response

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

Exampleen-US

legs
array: object
One leg per consecutive pair of break locations.
locations
array: object
The requested locations, snapped to the network and in the order visited.
status
integer
Zero on success.
status_message
string
Human-readable form of status.

ExampleFound route between points

summary
object
Totals for a trip or a single leg.
units
string
Units the lengths in this trip are expressed in.
Enumkilometersmiles
warnings
array: object
Non-fatal notes about the request, such as a parameter that was ignored. Absent when there are none.

Example response

Show response
{
  "trip": {
    "language": "en-US",
    "legs": [
      {
        "maneuvers": [
          {
            "bearing_after": 224,
            "begin_shape_index": 0,
            "cost": 8.08,
            "end_shape_index": 3,
            "instruction": "Drive southwest on Stevenson Street.",
            "length": 0.057,
            "street_names": [
              "Stevenson Street"
            ],
            "time": 6.904,
            "travel_mode": "drive",
            "travel_type": "car",
            "type": 1,
            "verbal_multi_cue": true,
            "verbal_post_transition_instruction": "Continue for 60 meters.",
            "verbal_pre_transition_instruction": "Drive southwest on Stevenson Street. Then You will arrive at your destination.",
            "verbal_succinct_transition_instruction": "Drive southwest. Then You will arrive at your destination."
          },
          {
            "bearing_before": 225,
            "begin_shape_index": 3,
            "cost": 0,
            "end_shape_index": 3,
            "instruction": "You have arrived at your destination.",
            "length": 0,
            "time": 0,
            "travel_mode": "drive",
            "travel_type": "car",
            "type": 4,
            "verbal_pre_transition_instruction": "You have arrived at your destination.",
            "verbal_transition_alert_instruction": "You will arrive at your destination."
          }
        ],
        "shape": "shmagAtbwmhFnA`BbAxAjQnV",
        "summary": {
          "cost": 8.08,
          "has_ferry": false,
          "has_highway": false,
          "has_time_restrictions": false,
          "has_toll": false,
          "length": 0.057,
          "max_lat": 37.788826,
          "max_lon": -122.400826,
          "min_lat": 37.788458,
          "min_lon": -122.401297,
          "time": 6.904
        }
      }
    ],
    "locations": [
      {
        "lat": 37.7891,
        "lon": -122.4011,
        "original_index": 0,
        "type": "break"
      },
      {
        "lat": 37.7887,
        "lon": -122.4016,
        "original_index": 1,
        "type": "via"
      }
    ],
    "status": 0,
    "status_message": "Found route between points",
    "summary": {
      "cost": 8.08,
      "has_ferry": false,
      "has_highway": false,
      "has_time_restrictions": false,
      "has_toll": false,
      "length": 0.057,
      "max_lat": 37.788826,
      "max_lon": -122.400826,
      "min_lat": 37.788458,
      "min_lon": -122.401297,
      "time": 6.904
    },
    "units": "kilometers"
  }
}

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

Reference: Valhalla map matching API reference