- HTTP request
- Request body
- Response body
- RouteMatrixOrigin
- RouteMatrixDestination
- ExtraComputation
- RouteMatrixElementCondition
- LocalizedValues
Takes in a list of origins and destinations and returns a stream containing route information for each combination of origin and destination.
NOTE: This method requires that you specify a response field mask in the input. You can provide the response field mask by using the URL parameter $fields
or fields
, or by using the HTTP/gRPC header X-Goog-FieldMask
(see the available URL parameters and headers). The value is a comma separated list of field paths. See this detailed documentation about how to construct the field paths.
For example, in this method:
- Field mask of all available fields (for manual inspection):
X-Goog-FieldMask: *
- Field mask of route durations, distances, element status, condition, and element indices (an example production setup):
X-Goog-FieldMask: originIndex,destinationIndex,status,condition,distanceMeters,duration
It is critical that you include status
in your field mask as otherwise all messages will appear to be OK. Google discourages the use of the wildcard (*
) response field mask, because:
- Selecting only the fields that you need helps our server save computation cycles, allowing us to return the result to you with a lower latency.
- Selecting only the fields that you need in your production job ensures stable latency performance. We might add more response fields in the future, and those new fields might require extra computation time. If you select all fields, or if you select all fields at the top level, then you might experience performance degradation because any new field we add will be automatically included in the response.
- Selecting only the fields that you need results in a smaller response size, and thus higher network throughput.
HTTP request
POST https://routes.googleapis.com/distanceMatrix/v2:computeRouteMatrix
The URL uses gRPC Transcoding syntax.
Request body
The request body contains data with the following structure:
JSON representation |
---|
{ "origins": [ { object ( |
Fields | |
---|---|
origins[] |
Required. Array of origins, which determines the rows of the response matrix. Several size restrictions apply to the cardinality of origins and destinations:
|
destinations[] |
Required. Array of destinations, which determines the columns of the response matrix. |
travel |
Optional. Specifies the mode of transportation. |
routing |
Optional. Specifies how to compute the route. The server attempts to use the selected routing preference to compute the route. If the routing preference results in an error or an extra long latency, an error is returned. You can specify this option only when the |
departure |
Optional. The departure time. If you don't set this value, then this value defaults to the time that you made the request. NOTE: You can only specify a A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: |
arrival |
Optional. The arrival time. NOTE: Can only be set when A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: |
language |
Optional. The BCP-47 language code, such as "en-US" or "sr-Latn". For more information, see Unicode Locale Identifier. See Language Support for the list of supported languages. When you don't provide this value, the display language is inferred from the location of the first origin. |
region |
Optional. The region code, specified as a ccTLD ("top-level domain") two-character value. For more information see Country code top-level domains. |
units |
Optional. Specifies the units of measure for the display fields. |
extra |
Optional. A list of extra computations which may be used to complete the request. Note: These extra computations may return extra fields on the response. These extra fields must also be specified in the field mask to be returned in the response. |
traffic |
Optional. Specifies the assumptions to use when calculating time in traffic. This setting affects the value returned in the duration field in the |
transit |
Optional. Specifies preferences that influence the route returned for |
Response body
Contains route information computed for an origin/destination pair in the v2.computeRouteMatrix API. This proto can be streamed to the client.
If successful, the response body contains data with the following structure:
JSON representation |
---|
{ "status": { object ( |
Fields | |
---|---|
status |
Error status code for this element. |
condition |
Indicates whether the route was found or not. Independent of status. |
distance |
The travel distance of the route, in meters. |
duration |
The length of time needed to navigate the route. If you set the A duration in seconds with up to nine fractional digits, ending with ' |
static |
The duration of traveling through the route without taking traffic conditions into consideration. A duration in seconds with up to nine fractional digits, ending with ' |
travel |
Additional information about the route. For example: restriction information and toll information |
fallback |
In some cases when the server is not able to compute the route with the given preferences for this particular origin/destination pair, it may fall back to using a different mode of computation. When fallback mode is used, this field contains detailed information about the fallback response. Otherwise this field is unset. |
localized |
Text representations of properties of the |
origin |
Zero-based index of the origin in the request. |
destination |
Zero-based index of the destination in the request. |
RouteMatrixOrigin
A single origin for ComputeRouteMatrixRequest
JSON representation |
---|
{ "waypoint": { object ( |
Fields | |
---|---|
waypoint |
Required. Origin waypoint |
route |
Optional. Modifiers for every route that takes this as the origin |
RouteMatrixDestination
A single destination for ComputeRouteMatrixRequest
JSON representation |
---|
{
"waypoint": {
object ( |
Fields | |
---|---|
waypoint |
Required. Destination waypoint |
ExtraComputation
Extra computations to perform while completing the request.
Enums | |
---|---|
EXTRA_COMPUTATION_UNSPECIFIED |
Not used. Requests containing this value will fail. |
TOLLS |
Toll information for the matrix element(s). |
RouteMatrixElementCondition
The condition of the route being returned.
Enums | |
---|---|
ROUTE_MATRIX_ELEMENT_CONDITION_UNSPECIFIED |
Only used when the status of the element is not OK. |
ROUTE_EXISTS |
A route was found, and the corresponding information was filled out for the element. |
ROUTE_NOT_FOUND |
No route could be found. Fields containing route information, such as distanceMeters or duration , will not be filled out in the element. |
LocalizedValues
Text representations of certain properties.
JSON representation |
---|
{ "distance": { object ( |
Fields | |
---|---|
distance |
Travel distance represented in text form. |
duration |
Duration represented in text form taking traffic conditions into consideration. Note: If traffic information was not requested, this value is the same value as staticDuration. |
static |
Duration represented in text form without taking traffic conditions into consideration. |
transit |
Transit fare represented in text form. |