A route matrix request takes as input an array of origin and destination waypoints. The Routes API then calculates the route from each origin waypoint to each destination waypoint. For example, if you specify two origin waypoints and two destination waypoints, the API then calculates four separate routes.
The API response contains an array, where each array element corresponds to the route from one origin waypoint to one destination waypoint. Therefore, if you specify two origin waypoints and two destination waypoints, the response array contains four elements, one for each computed route.
Using the response, you can provide your customers with different route options and then let the user select the appropriate route for their requirements.
About field masks
When you call a method to compute a route, you must specify a field mask that defines which fields you want returned in the response. There is no default list of returned fields. If you omit this list, the methods return an error.
The examples in this document show the entire response object without taking field masks into consideration. In a production environment, your response would only include the fields that you explicitly specify in the field mask.
For more information, see Choose what information to return.
About displaying copyrights
You must include the following copyright statement when displaying the results to your users:
Powered by Google, ©YEAR Google
For example:
Powered by Google, ©2023 Google
Identify the route in the response
Use the originIndex
and destinationIndex
response properties to identify
each route in the response. These properties contain the zero-based index of
the input origin and input destination waypoints used to calculate the
route. That means the first origin waypoint and the first destination waypoint
in the request are at array index 0.
For example, a route in the response contains:
"originIndex": 1, "destinationIndex": 0
These properties indicate that the route was calculated from the origin waypoint at index 1 in the input array, and from the destination waypoint at index 0.
For the next route:
"originIndex": 4, "destinationIndex": 1
The route was calculated from the origin waypoint at index 4 in the input array, and from the destination waypoint at index 1 in the input array.
About the response
The JSON object representing the API response contains an array, where each array element defines the route from one origin waypoint to one destination waypoint.
Along with the originIndex
and destinationIndex
properties, each route
contains information specific to that route, such as distanceMeters
,
duration
, and travelAdvisory
.
The response has the form:
[ // One array element for each combination of origin and destination waypoints. { // The route for source waypoint 0 and destination waypoint 0. "originIndex": 0, "destinationIndex": 0, "status": { object (Status) }, "condition": enum (RouteMatrixElementCondition), "distanceMeters": integer, "duration": string, "staticDuration": string, "travelAdvisory": { object (RouteTravelAdvisory) }, "fallbackInfo": { object (FallbackInfo) } } { // The route for source waypoint 0 and destination waypoint 1. "originIndex": 0, "destinationIndex": 1, "status": { object (Status) }, "condition": enum (RouteMatrixElementCondition), "distanceMeters": integer, "duration": string, "staticDuration": string, "travelAdvisory": { object (RouteTravelAdvisory) }, "fallbackInfo": { object (FallbackInfo) } } … ]