Overview
Calculate a distance and/or travel-time matrix between multiple locations. Use this tool when the user needs to:- find the nearest driver, vehicle, store, or facility
- compare several destinations
- compare multiple origin-destination pairs
- build a distance or travel-time matrix
route instead.
Input
coordinates array.
For example:
[row][column] represents the route from that source to that destination.
For example:
0 to coordinate 2.
The response includes sources and destinations with the original coordinate indices so the matrix can be mapped back to the user’s locations.
Sources and destinations
Optionalsources and destinations restrict the matrix to subsets of the coordinate indices.
For example:
0 to coordinates 1 and 2.
Annotations
Use:duration— travel time in secondsdistance— distance in meters
Motorcycle routing
Set:profile.
Nearest-driver example
For a question such as:Which driver is closest to the customer?Keep the locations in a fixed order:
- Use
[0]as the source. - Use the driver indices as destinations.
- Read the corresponding values from the first matrix row.
- Ignore
nullvalues. - Choose the smallest distance or duration, depending on the user’s request.
Output
durations are in seconds.
distances are in meters.
A matrix value of null means that the origin-destination pair is unreachable.
Never interpret null as zero.
If the user provides place names or addresses instead of coordinates, call geocode first for every place. Keep the locations in the same order when constructing the matrix request.
