Stay organized with collections Save and categorize content based on your preferences.
This product or feature is in Preview (pre-GA). Pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. Pre-GA Offerings are covered by the Google Maps Platform Service Specific Terms. For more information, see the launch stage descriptions.You can calculate the distance and duration of a route for multiple origins and destinations by using the ComputeRouteMatrix
method of the Routes Preferred API. ComputeRouteMatrix
supports both streaming gRPC calls and REST HTTP calls.
Given a list of origin and destination pairs, ComputeRouteMatrix
calculates the distance and duration of a route starting at each origin and ending at each destination. Each element of the stream corresponds to the information for a single route.
The ComputeRouteMatrix
method has several advantages over the Distance Matrix Service:
ComputeRouteMatrix
has fine-grained options for traffic calculation, letting you make quality-latency tradeoff decisions.Before you can use the ComputeRouteMatrix
method in your code, you must enable it. For more information on enabling Routes Preferred API methods, see Getting Started.
The ComputeRouteMatrix
method is available through the Routes Preferred v1 endpoint.
See the following documentation for more detailed information:
The following generic steps describe how to use gRPC to call the ComputeRouteMatrix
method:
Check out the necessary protobuffers from the googleapis repository:
https://github.com/googleapis/googleapis/tree/master/google/maps/routes
Note that some build systems, such as Go, may automatically do this for you.
Using your preferred language and set of build tools, generate the relevant protobuffer code.
Generate your request. Two required pieces of metadata must be sent with the request:
X-Goog-Fieldmask must be set to a comma separated list of the fields you require from the response. For example, X-Goog-FieldMask: originIndex,destinationIndex,duration,distanceMeters,status. You can use the wildcard character (*) to denote all fields, but that is discouraged. Use the wildcard character to test and understand the API response, but explicitly list the fields you want in the field mask in your production code.
For more information on how to construct the field mask string, see https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/field_mask.proto. Note that disabling fields you do not need can reduce latency since those fields may require further computation. Your latency will stay stable if you specify the fields you need and new fields that require more computation are added later.
Send your request to routespreferred.googleapis.com:443
.You must use the TLS protocol.
For examples of using the ComputeRouteMatrix
method, see Computing a Route Matrix (Beta) Examples.
One distinguishing feature of the ComputeRouteMatrix
method is that error codes can be returned either for the entire stream or for individual elements. For example, the stream connection returns an error if the request is malformed (for example, it has zero origins). However, if an error applies to just a few elements of the stream (for example, setting an invalid Place ID for an origin), then only the elements affected by the error contain error codes.
The elements returned by the stream are not guaranteed to be returned in any order. Because of this, each element contains an origin_index
and a destination_index
. For the origins and destinations specified by the request, the route origin is equivalent to origins[origin_index]
for a given element and the route destination is is equivalent to destinations[destination_index]
. These arrays are zero-indexed. It is important to store the origin and destination list orders.
For information on calculating toll fees, see Calculate toll fees.
For examples of calculating toll fees, see Computing a Route Matrix Examples.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-14 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[[["The `ComputeRouteMatrix` method in the Routes Preferred API calculates distances and durations for multiple origin-destination pairs, offering advantages like streaming results and traffic calculation options."],["It's necessary to enable the `ComputeRouteMatrix` method and understand quota limits before implementation, ensuring compliance with Google Maps Platform terms."],["The method can be accessed through gRPC or REST, with specific steps outlined for using gRPC, including generating protobuffer code and configuring requests."],["Responses include `origin_index` and `destination_index` to correlate results with input data since the order of elements is not guaranteed."],["Toll fee calculation functionality is available within `ComputeRouteMatrix`, allowing developers to incorporate toll costs into route planning."]]],["The `ComputeRouteMatrix` method of the Routes Preferred API calculates route distance and duration for multiple origins and destinations via streaming gRPC or REST HTTP calls. It offers lower latency, fine-grained traffic options, higher availability, waypoint specifications, and toll information. To use it, enable the method, and send requests with API key and field mask. The method returns elements with `origin_index` and `destination_index`. Error codes can be returned for the entire stream or per individual element.\n"]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4