Calculate a source-to-target route matrix
Signed in? Open this endpoint in the dashboard playground, which uses your organization automatically. Signed out, use Try in Playground below with your API key.
Calculates travel distances and times from every source to every target (Valhalla sources_to_targets).
- Send a JSON body with
mode,sourcesandtargets. Eachlocationis[longitude, latitude]. sources_to_targets[i][j]describes the route fromsources[i]totargets[j].- Repeat the same locations in
sourcesandtargetsfor a square all-to-all matrix. distanceortimeisnullwhen no route exists for a pair.- Size limit: 1 to 1000 sources and 1 to 1000 targets, each checked separately.
Deviation (approximated): Geoapify caps a regular call at 1,000 cells in total; this service caps sources and targets at 1000 each (see the sources field).
Deviation (ignored): traffic is accepted and ignored; durations are always free-flow.
Deviation (empty): response locations carry original_location only, no road-snapped location.
Not supported: modes transit and approximated_transit (400), the Geoapify per-pair and sum-of-distances limits, and asynchronous batch calls (/batch is not in v1).
curl -X POST 'https://api.data.graphitelab.ai/v1/routematrix?apiKey=YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{"mode":"drive","sources":[{"location":[-86.158,39.768]}],"targets":[{"location":[-86.1,39.8]}]}'apiKey<token>Your API key from the dashboard, sent as ?apiKey=<key>.
Route Matrix configuration. The request body must be JSON.
application/json- body
mode*stringTravel profile used to calculate speeds, access rules and road restrictions. drive represents a passenger car.
Deviation (unsupported): transit and approximated_transit are rejected with 400 (no transit data); they are not accepted for matrices on Geoapify either.
"walk""hike""scooter""motorcycle""drive""light_truck""bicycle""mountain_bike""road_bike""bus""medium_truck""truck""truck_dangerous_goods""heavy_truck""long_truck"sources*array<>Origin locations. Each source produces one row in sources_to_targets.
Deviation (approximated): this service enforces 1 to 1000 sources and 1 to 1000 targets independently, not Geoapify's 1,000 total cells (sources x targets). Large matrices are computed in blocks of 150 x 150 (50 x 50 for scooter, motorcycle and bus), so very large requests are slow.
1 <= items <= 1000targets*array<>Destination locations. Each target produces one column in every sources_to_targets row. Same limits as sources.
1 <= items <= 1000avoid?array<>Road features, locations or polygons the router should avoid (up to 100 rules).
items <= 100traffic?stringTraffic model for motorized modes.
Deviation (ignored): accepted for compatibility; durations are always free-flow and the response always reports free_flow.
"free_flow""free_flow""approximated"type?stringRoute preference. balanced balances time and distance; short prioritizes distance; less_maneuvers penalizes turns and is only valid for motorized modes (400 otherwise).
"balanced""balanced""short""less_maneuvers"max_speed?numberMaximum speed for driving, truck, motorcycle, scooter and bus modes. 10 to 252 km/h with units=metric, or 6.5 to 155 mph with units=imperial; outside that range returns 400. Ignored for walking and cycling modes.
6.5 <= value <= 252units?stringUnit system for matrix distances. metric returns meters; imperial returns miles (3 decimals).
"metric""metric""imperial"Matrix rows correspond to sources; columns to targets. Distances use the requested unit system, times are in seconds.
application/json- response
sources*array<>targets*array<>sources_to_targets*array<array<>>sources_to_targets[i][j] is the route from sources[i] to targets[j].
units*string"metric""imperial"distance_units*string"meters""miles"mode*string"walk""hike""scooter""motorcycle""drive""light_truck""bicycle""mountain_bike""road_bike""bus""medium_truck""truck""truck_dangerous_goods""heavy_truck""long_truck"type?string"balanced""short""less_maneuvers"max_speed?numberEcho of the request value, present only when sent.
avoid?array<>Echo of the request rules, present only when sent.
traffic?stringAlways free_flow (see the request traffic deviation).
"free_flow""approximated"curl -X POST 'https://api.data.graphitelab.ai/v1/routematrix' \ -H 'Content-Type: application/json' \ -d '{ "mode": "drive", "sources": [ { "location": [ -86.158068, 39.768403 ] }, { "location": [ -86.1581, 39.7684 ] } ], "targets": [ { "location": [ -86.1349, 39.7817 ] }, { "location": [ -86.2, 39.75 ] } ]}'{ "sources": [ { "original_location": [ -86.158068, 39.768403 ] }, { "original_location": [ -86.1581, 39.7684 ] } ], "targets": [ { "original_location": [ -86.1349, 39.7817 ] }, { "original_location": [ -86.2, 39.75 ] } ], "sources_to_targets": [ [ { "distance": 2900, "time": 298, "source_index": 0, "target_index": 0 }, { "distance": 4956, "time": 426, "source_index": 0, "target_index": 1 } ], [ { "distance": 2907, "time": 299, "source_index": 1, "target_index": 0 }, { "distance": 4963, "time": 427, "source_index": 1, "target_index": 1 } ] ], "units": "metric", "distance_units": "meters", "mode": "drive", "type": "balanced", "traffic": "free_flow"}