Compute Route Matrix is a method in the Routes API service that accepts an HTTPS request and returns distances and travel times for a matrix of routes between different origin and destination locations. Calculate travel times and distances for multiple destinations for up to 625 route elements.
Need Driving Routes? If you are interested in route directions, see Compute Routes Overview.
Migrating? If you are migrating from the Distance Matrix API (Legacy), see migration instructions starting with Why migrate to the Routes API.
Why use Compute Route Matrix
With Compute Route Matrix, you can determine the most efficient routes for dispatch scheduling, such as:
How best to assign a set of workers to pick up a series of packages
Determine the best warehouse from which to ship packages to their final destination
What you can do with Compute Route Matrix?
With Compute Route Matrix, you can get a matrix of possible routes between many start and end locations. You can specify multiple origins and destinations per server-side request with the number of origins times the number of destinations up to 625. You can stream elements of the response before the entire matrix has been calculated, lowering response latency.
You can request these kinds of route data to determine the most efficient way to route passengers, shipments, or workers between multiple origins and destinations:
Distance in kilometers or miles for a selected travel mode
Estimated travel time in traffic
How Compute Route Matrix works
The ComputeRouteMatrix
method accepts an HTTP POST request with
a JSON request body that contains the request details. Required are at least one
origin, two or more destinations, travelMode, and a field mask to specify which
fields to return.
Example
curl -X POST -d '{ "origins": [ { "waypoint": { "location": { "latLng": { "latitude": 37.420761, "longitude": -122.081356 } } } }, { "waypoint": { "location": { "latLng": { "latitude": 37.403184, "longitude": -122.097371 } } } } ], "destinations": [ { "waypoint": { "location": { "latLng": { "latitude": 37.420999, "longitude": -122.086894 } } } }, { "waypoint": { "location": { "latLng": { "latitude": 37.383047, "longitude": -122.044651 } } } } ], "travelMode": "DRIVE" }' \ -H 'Content-Type: application/json' -H 'X-Goog-Api-Key: YOUR_API_KEY' \ -H 'X-Goog-FieldMask: originIndex,destinationIndex,duration,distanceMeters,status,condition' \ 'https://routes.googleapis.com/distanceMatrix/v2:computeRouteMatrix'
The response contains the possible routes for the combination of all origin and destination waypoints.
Resources
The following table summarizes the resources available through the Routes API Compute Route Matrix method, along with the data it returns.
Data resources | Data returned | Return format |
---|---|---|
ComputeRouteMatrix | Returns an array of routes from one origin waypoint to one destination waypoint. | JSON |
How to use Compute Route Matrix
1 | Get set up | Start with Set up your Google Cloud project and complete the setup instructions that follow. |
2 | Understand how the Routes API bills | For information, see Usage and billing. |
3 | Compute matrix of routes and review the response | For more information, see Get a route matrix and Review the route matrix response. |
Available client libraries
For a list of the available client libraries for Compute Route Matrix, see Client libraries.
What's next
- Get a route matrix
- Available route matrix options
- Choose what information to return
- Migrate from Distance Matrix API (Legacy)
- Migrate from the Routes API preview to GA