In Compute Routes API, at a minimum, you pass in an “origin” location and a “destination” location. That is the equivalent of doing a 1-by-1 Route Matrix call. In the response, you’ll get:
- an array of “routes” (the best route first, with additional alternate routes if applicable)
- each route is composed of an array of “legs” (a simple origin-to-destination route will have only 1 leg)
The legs are what you’re interested in. The leg object is where the “distance” and “duration” properties reside (similar to what you’d get from Route Matrix). Here is a simplified view of that structure (there are many other properties, but this is what you’re after to get just the drive time & distance):
{
"routes": [
{
"legs": [
{
"distance": {
"value": 1609,
"text": "1 mi"
},
"duration": {
"value": 600,
"text": "10 min"
}
}
]
}
]
}Waypoints to the rescue
Now, the potential savings of Compute Routes vs. Route Matrix come in with the “waypoints” parameter. Waypoints are the stops you make along the way between your origin and destination (e.g. stopping at the grocery store along my commute home would be a waypoint between my work origin and home destination). Waypoints split a route into multiple “legs” and, as shown above, each leg has its own distance and duration. More on waypoints here: https://developers.google.com/maps/documentation/routes/intermed_waypoints
By carefully structuring the manner in which you insert appointments as waypoints on a Routes API route, you can potentially combine what are currently multiple Route Matrix calls into a single Routes call. A single Routes request (up to 9 waypoint) costs the same as only a single Route Matrix element. A single Routes Pro request (from 10-23 waypoints) is the same cost as a mere two Route Matrix elements. See the Maps Platform pricing sheet for details.
See an example of using intermediate waypoints here: https://developers.google.com/maps/documentation/routes/intermed_waypoints#example_-_set_an_intermediate_waypoint
Comments
0 comments
Please sign in to leave a comment.