AI-generated Key Takeaways
-
The Routes API offers two primary methods:
ComputeRouteMatrix
for calculating route information between multiple origins and destinations andComputeRoutes
for finding routes between a single origin and destination, including optional waypoints. -
Developers can customize route calculations by specifying travel mode, routing preferences (like traffic awareness), departure/arrival times, and route modifiers such as avoiding tolls or highways.
-
Response field masks are crucial for performance and stability, allowing developers to retrieve only the necessary data, reducing latency and response size.
-
The API provides comprehensive route details including distance, duration, traffic conditions, navigation instructions, toll information, and alternative routes when available.
-
Various data structures and enumerations support the API's functionality, including waypoints, route modifiers, transit preferences, polyline encodings, and toll passes, enabling detailed route planning and customization.
Index
Routes
(interface)ComputeRouteMatrixRequest
(message)ComputeRouteMatrixRequest.ExtraComputation
(enum)ComputeRoutesRequest
(message)ComputeRoutesRequest.ExtraComputation
(enum)ComputeRoutesRequest.ReferenceRoute
(enum)ComputeRoutesResponse
(message)FallbackInfo
(message)FallbackReason
(enum)FallbackRoutingMode
(enum)GeocodedWaypoint
(message)GeocodingResults
(message)LocalizedTime
(message)Location
(message)Maneuver
(enum)NavigationInstruction
(message)Polyline
(message)PolylineDetails
(message)PolylineDetails.FlyoverInfo
(message)PolylineDetails.NarrowRoadInfo
(message)PolylineDetails.PolylinePointIndex
(message)PolylineDetails.RoadFeatureState
(enum)PolylineEncoding
(enum)PolylineQuality
(enum)Route
(message)Route.RouteLocalizedValues
(message)RouteLabel
(enum)RouteLeg
(message)RouteLeg.RouteLegLocalizedValues
(message)RouteLeg.StepsOverview
(message)RouteLeg.StepsOverview.MultiModalSegment
(message)RouteLegStep
(message)RouteLegStep.RouteLegStepLocalizedValues
(message)RouteLegStepTransitDetails
(message)RouteLegStepTransitDetails.TransitDetailsLocalizedValues
(message)RouteLegStepTransitDetails.TransitStopDetails
(message)RouteLegStepTravelAdvisory
(message)RouteLegTravelAdvisory
(message)RouteMatrixDestination
(message)RouteMatrixElement
(message)RouteMatrixElement.LocalizedValues
(message)RouteMatrixElementCondition
(enum)RouteMatrixOrigin
(message)RouteModifiers
(message)RouteTravelAdvisory
(message)RouteTravelMode
(enum)RoutingPreference
(enum)SpeedReadingInterval
(message)SpeedReadingInterval.Speed
(enum)TollInfo
(message)TollPass
(enum)TrafficModel
(enum)TransitAgency
(message)TransitLine
(message)TransitPreferences
(message)TransitPreferences.TransitRoutingPreference
(enum)TransitPreferences.TransitTravelMode
(enum)TransitStop
(message)TransitVehicle
(message)TransitVehicle.TransitVehicleType
(enum)Units
(enum)VehicleEmissionType
(enum)VehicleInfo
(message)Waypoint
(message)
Routes
The Routes API.
ComputeRouteMatrix |
---|
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 For example, in this method:
It is critical that you include
|
ComputeRoutes |
---|
Returns the primary route along with optional alternate routes, given a set of terminal and intermediate waypoints. NOTE: This method requires that you specify a response field mask in the input. You can provide the response field mask by using URL parameter For example, in this method:
Google discourage the use of the wildcard (
|
ComputeRouteMatrixRequest
ComputeRouteMatrix request message
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_mode |
Optional. Specifies the mode of transportation. |
routing_preference |
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_time |
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 |
arrival_time |
Optional. The arrival time. NOTE: Can only be set when |
language_code |
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_code |
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_computations[] |
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_model |
Optional. Specifies the assumptions to use when calculating time in traffic. This setting affects the value returned in the duration field in the |
transit_preferences |
Optional. Specifies preferences that influence the route returned for |
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). |
ComputeRoutesRequest
ComputeRoutes request message.
Fields | |
---|---|
origin |
Required. Origin waypoint. |
destination |
Required. Destination waypoint. |
intermediates[] |
Optional. A set of waypoints along the route (excluding terminal points), for either stopping at or passing by. Up to 25 intermediate waypoints are supported. |
travel_mode |
Optional. Specifies the mode of transportation. |
routing_preference |
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, then an error is returned. You can specify this option only when the |
polyline_quality |
Optional. Specifies your preference for the quality of the polyline. |
polyline_encoding |
Optional. Specifies the preferred encoding for the polyline. |
departure_time |
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 |
arrival_time |
Optional. The arrival time. NOTE: This field is ignored when requests specify a |
compute_alternative_routes |
Optional. Specifies whether to calculate alternate routes in addition to the route. No alternative routes are returned for requests that have intermediate waypoints. |
route_modifiers |
Optional. A set of conditions to satisfy that affect the way routes are calculated. |
language_code |
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 route request. |
region_code |
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. These fields include the |
optimize_waypoint_order |
Optional. If set to true, the service attempts to minimize the overall cost of the route by re-ordering the specified intermediate waypoints. The request fails if any of the intermediate waypoints is a |
requested_reference_routes[] |
Optional. Specifies what reference routes to calculate as part of the request in addition to the default route. A reference route is a route with a different route calculation objective than the default route. For example a |
extra_computations[] |
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_model |
Optional. Specifies the assumptions to use when calculating time in traffic. This setting affects the value returned in the duration field in the |
transit_preferences |
Optional. Specifies preferences that influence the route returned for |
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 route(s). |
FUEL_CONSUMPTION |
Estimated fuel consumption for the route(s). |
TRAFFIC_ON_POLYLINE |
Traffic aware polylines for the route(s). |
HTML_FORMATTED_NAVIGATION_INSTRUCTIONS |
NavigationInstructions presented as a formatted HTML text string. This content is meant to be read as-is. This content is for display only. Do not programmatically parse it. |
FLYOVER_INFO_ON_POLYLINE |
Flyover information for the route(s). The routes.polyline_details.flyover_info fieldmask must be specified to return this information. This data will only currently be populated for certain metros in India. This feature is experimental, and the SKU/charge is subject to change. |
NARROW_ROAD_INFO_ON_POLYLINE |
Narrow road information for the route(s). The routes.polyline_details.narrow_road_info fieldmask must be specified to return this information. This data will only currently be populated for certain metros in India. This feature is experimental, and the SKU/charge is subject to change. |
ReferenceRoute
A supported reference route on the ComputeRoutesRequest.
Enums | |
---|---|
REFERENCE_ROUTE_UNSPECIFIED |
Not used. Requests containing this value fail. |
FUEL_EFFICIENT |
Fuel efficient route. |
SHORTER_DISTANCE |
Route with shorter travel distance. This is an experimental feature. For For This feature is not compatible with any other travel modes, via intermediate waypoints, or |
ComputeRoutesResponse
ComputeRoutes the response message.
Fields | |
---|---|
routes[] |
Contains an array of computed routes (up to three) when you specify |
fallback_info |
In some cases when the server is not able to compute the route results with all of the input preferences, it may fallback to using a different way of computation. When fallback mode is used, this field contains detailed info about the fallback response. Otherwise this field is unset. |
geocoding_results |
Contains geocoding response info for waypoints specified as addresses. |
FallbackInfo
Information related to how and why a fallback result was used. If this field is set, then it means the server used a different routing mode from your preferred mode as fallback.
Fields | |
---|---|
routing_mode |
Routing mode used for the response. If fallback was triggered, the mode may be different from routing preference set in the original client request. |
reason |
The reason why fallback response was used instead of the original response. This field is only populated when the fallback mode is triggered and the fallback response is returned. |
FallbackReason
Reasons for using fallback response.
Enums | |
---|---|
FALLBACK_REASON_UNSPECIFIED |
No fallback reason specified. |
SERVER_ERROR |
A server error happened while calculating routes with your preferred routing mode, but we were able to return a result calculated by an alternative mode. |
LATENCY_EXCEEDED |
We were not able to finish the calculation with your preferred routing mode on time, but we were able to return a result calculated by an alternative mode. |
FallbackRoutingMode
Actual routing mode used for returned fallback response.
Enums | |
---|---|
FALLBACK_ROUTING_MODE_UNSPECIFIED |
Not used. |
FALLBACK_TRAFFIC_UNAWARE |
Indicates the TRAFFIC_UNAWARE was used to compute the response. |
FALLBACK_TRAFFIC_AWARE |
Indicates the TRAFFIC_AWARE was used to compute the response. |
GeocodedWaypoint
Details about the locations used as waypoints. Only populated for address waypoints. Includes details about the geocoding results for the purposes of determining what the address was geocoded to.
Fields | |
---|---|
geocoder_status |
Indicates the status code resulting from the geocoding operation. |
type[] |
The type(s) of the result, in the form of zero or more type tags. Supported types: Address types and address component types. |
partial_match |
Indicates that the geocoder did not return an exact match for the original request, though it was able to match part of the requested address. You may wish to examine the original request for misspellings and/or an incomplete address. |
place_id |
The place ID for this result. |
intermediate_waypoint_request_index |
The index of the corresponding intermediate waypoint in the request. Only populated if the corresponding waypoint is an intermediate waypoint. |
GeocodingResults
Contains
for origin, destination and intermediate waypoints. Only populated for address waypoints.GeocodedWaypoints
Fields | |
---|---|
origin |
Origin geocoded waypoint. |
destination |
Destination geocoded waypoint. |
intermediates[] |
A list of intermediate geocoded waypoints each containing an index field that corresponds to the zero-based position of the waypoint in the order they were specified in the request. |
LocalizedTime
Localized description of time.
Fields | |
---|---|
time |
The time specified as a string in a given time zone. |
time_zone |
Contains the time zone. The value is the name of the time zone as defined in the IANA Time Zone Database, e.g. "America/New_York". |
Location
Encapsulates a location (a geographic point, and an optional heading).
Fields | |
---|---|
lat_lng |
The waypoint's geographic coordinates. |
heading |
The compass heading associated with the direction of the flow of traffic. This value specifies the side of the road for pickup and drop-off. Heading values can be from 0 to 360, where 0 specifies a heading of due North, 90 specifies a heading of due East, and so on. You can use this field only for |
Maneuver
A set of values that specify the navigation action to take for the current step (for example, turn left, merge, or straight).
Enums | |
---|---|
MANEUVER_UNSPECIFIED |
Not used. |
TURN_SLIGHT_LEFT |
Turn slightly to the left. |
TURN_SHARP_LEFT |
Turn sharply to the left. |
UTURN_LEFT |
Make a left u-turn. |
TURN_LEFT |
Turn left. |
TURN_SLIGHT_RIGHT |
Turn slightly to the right. |
TURN_SHARP_RIGHT |
Turn sharply to the right. |
UTURN_RIGHT |
Make a right u-turn. |
TURN_RIGHT |
Turn right. |
STRAIGHT |
Go straight. |
RAMP_LEFT |
Take the left ramp. |
RAMP_RIGHT |
Take the right ramp. |
MERGE |
Merge into traffic. |
FORK_LEFT |
Take the left fork. |
FORK_RIGHT |
Take the right fork. |
FERRY |
Take the ferry. |
FERRY_TRAIN |
Take the train leading onto the ferry. |
ROUNDABOUT_LEFT |
Turn left at the roundabout. |
ROUNDABOUT_RIGHT |
Turn right at the roundabout. |
DEPART |
Initial maneuver. |
NAME_CHANGE |
Used to indicate a street name change. |
Polyline
Encapsulates an encoded polyline.
Fields | |
---|---|
Union field polyline_type . Encapsulates the type of polyline. Defaults to encoded_polyline. polyline_type can be only one of the following: |
|
encoded_polyline |
The string encoding of the polyline using the polyline encoding algorithm |
geo_json_linestring |
Specifies a polyline using the GeoJSON LineString format. |
PolylineDetails
Details corresponding to a given index or contiguous segment of a polyline. Given a polyline with points P_0, P_1, ... , P_N (zero-based index), the PolylineDetails
defines an interval and associated metadata.
Fields | |
---|---|
flyover_info[] |
Flyover details along the polyline. |
narrow_road_info[] |
Narrow road details along the polyline. |
FlyoverInfo
Encapsulates information about flyovers along the polyline.
Fields | |
---|---|
flyover_presence |
Output only. Denotes whether a flyover exists for a given stretch of the polyline. |
polyline_point_index |
The location of flyover related information along the polyline. |
NarrowRoadInfo
Encapsulates information about narrow roads along the polyline.
Fields | |
---|---|
narrow_road_presence |
Output only. Denotes whether a narrow road exists for a given stretch of the polyline. |
polyline_point_index |
The location of narrow road related information along the polyline. |
PolylinePointIndex
Encapsulates the start and end indexes for a polyline detail. For instances where the data corresponds to a single point, start_index
and end_index
will be equal.
Fields | |
---|---|
start_index |
The start index of this detail in the polyline. |
end_index |
The end index of this detail in the polyline. |
RoadFeatureState
Encapsulates the states of road features along a stretch of polyline.
Enums | |
---|---|
ROAD_FEATURE_STATE_UNSPECIFIED |
The road feature's state was not computed (default value). |
EXISTS |
The road feature exists. |
DOES_NOT_EXIST |
The road feature does not exist. |
PolylineEncoding
Specifies the preferred type of polyline to be returned.
Enums | |
---|---|
POLYLINE_ENCODING_UNSPECIFIED |
No polyline type preference specified. Defaults to ENCODED_POLYLINE . |
ENCODED_POLYLINE |
Specifies a polyline encoded using the polyline encoding algorithm. |
GEO_JSON_LINESTRING |
Specifies a polyline using the GeoJSON LineString format |
PolylineQuality
A set of values that specify the quality of the polyline.
Enums | |
---|---|
POLYLINE_QUALITY_UNSPECIFIED |
No polyline quality preference specified. Defaults to OVERVIEW . |
HIGH_QUALITY |
Specifies a high-quality polyline - which is composed using more points than OVERVIEW , at the cost of increased response size. Use this value when you need more precision. |
OVERVIEW |
Specifies an overview polyline - which is composed using a small number of points. Use this value when displaying an overview of the route. Using this option has a lower request latency compared to using the HIGH_QUALITY option. |
Route
Contains a route, which consists of a series of connected road segments that join beginning, ending, and intermediate waypoints.
Fields | |
---|---|
route_labels[] |
Labels for the |
legs[] |
A collection of legs (path segments between waypoints) that make up the route. Each leg corresponds to the trip between two non- |
distance_meters |
The travel distance of the route, in meters. |
duration |
The length of time needed to navigate the route. If you set the |
static_duration |
The duration of travel through the route without taking traffic conditions into consideration. |
polyline |
The overall route polyline. This polyline is the combined polyline of all |
description |
A description of the route. |
warnings[] |
An array of warnings to show when displaying the route. |
viewport |
The viewport bounding box of the polyline. |
travel_advisory |
Additional information about the route. |
optimized_intermediate_waypoint_index[] |
If you set |
localized_values |
Text representations of properties of the |
route_token |
An opaque token that can be passed to Navigation SDK to reconstruct the route during navigation, and, in the event of rerouting, honor the original intention when the route was created. Treat this token as an opaque blob. Don't compare its value across requests as its value may change even if the service returns the exact same route. NOTE: |
polyline_details |
Contains information about details along the polyline. |
RouteLocalizedValues
Text representations of certain properties.
Fields | |
---|---|
distance |
Travel distance represented in text form. |
duration |
Duration, represented in text form and localized to the region of the query. Takes traffic conditions into consideration. Note: If you did not request traffic information, this value is the same value as |
static_duration |
Duration without taking traffic conditions into consideration, represented in text form. |
transit_fare |
Transit fare represented in text form. |
RouteLabel
Labels for the
that are useful to identify specific properties of the route to compare against others.Route
Enums | |
---|---|
ROUTE_LABEL_UNSPECIFIED |
Default - not used. |
DEFAULT_ROUTE |
The default "best" route returned for the route computation. |
DEFAULT_ROUTE_ALTERNATE |
An alternative to the default "best" route. Routes like this will be returned when is specified. |
FUEL_EFFICIENT |
Fuel efficient route. Routes labeled with this value are determined to be optimized for Eco parameters such as fuel consumption. |
SHORTER_DISTANCE |
Shorter travel distance route. This is an experimental feature. |
RouteLeg
Contains a segment between non-via
waypoints.
Fields | |
---|---|
distance_meters |
The travel distance of the route leg, in meters. |
duration |
The length of time needed to navigate the leg. If the |
static_duration |
The duration of travel through the leg, calculated without taking traffic conditions into consideration. |
polyline |
The overall polyline for this leg that includes each |
start_location |
The start location of this leg. This location might be different from the provided |
end_location |
The end location of this leg. This location might be different from the provided |
steps[] |
An array of steps denoting segments within this leg. Each step represents one navigation instruction. |
travel_advisory |
Contains the additional information that the user should be informed about, such as possible traffic zone restrictions, on a route leg. |
localized_values |
Text representations of properties of the |
steps_overview |
Overview information about the steps in this |
RouteLegLocalizedValues
Text representations of certain properties.
Fields | |
---|---|
distance |
Travel distance represented in text form. |
duration |
Duration, represented in text form and localized to the region of the query. Takes traffic conditions into consideration. Note: If you did not request traffic information, this value is the same value as static_duration. |
static_duration |
Duration without taking traffic conditions into consideration, represented in text form. |
StepsOverview
Provides overview information about a list of RouteLegStep
s.
Fields | |
---|---|
multi_modal_segments[] |
Summarized information about different multi-modal segments of the |
MultiModalSegment
Provides summarized information about different multi-modal segments of the RouteLeg.steps
. A multi-modal segment is defined as one or more contiguous RouteLegStep
that have the same RouteTravelMode
. This field is not populated if the RouteLeg
does not contain any multi-modal segments in the steps.
Fields | |
---|---|
navigation_instruction |
NavigationInstruction for the multi-modal segment. |
travel_mode |
The travel mode of the multi-modal segment. |
step_start_index |
The corresponding |
step_end_index |
The corresponding |
RouteLegStep
Contains a segment of a
. A step corresponds to a single navigation instruction. Route legs are made up of steps.RouteLeg
Fields | |
---|---|
distance_meters |
The travel distance of this step, in meters. In some circumstances, this field might not have a value. |
static_duration |
The duration of travel through this step without taking traffic conditions into consideration. In some circumstances, this field might not have a value. |
polyline |
The polyline associated with this step. |
start_location |
The start location of this step. |
end_location |
The end location of this step. |
navigation_instruction |
Navigation instructions. |
travel_advisory |
Contains the additional information that the user should be informed about, such as possible traffic zone restrictions, on a leg step. |
localized_values |
Text representations of properties of the |
transit_details |
Details pertaining to this step if the travel mode is |
travel_mode |
The travel mode used for this step. |
RouteLegStepLocalizedValues
Text representations of certain properties.
Fields | |
---|---|
distance |
Travel distance represented in text form. |
static_duration |
Duration without taking traffic conditions into consideration, represented in text form. |
RouteLegStepTransitDetails
Additional information for the RouteLegStep
related to TRANSIT
routes.
Fields | |
---|---|
stop_details |
Information about the arrival and departure stops for the step. |
localized_values |
Text representations of properties of the |
headsign |
Specifies the direction in which to travel on this line as marked on the vehicle or at the departure stop. The direction is often the terminus station. |
headway |
Specifies the expected time as a duration between departures from the same stop at this time. For example, with a headway seconds value of 600, you would expect a ten minute wait if you should miss your bus. |
transit_line |
Information about the transit line used in this step. |
stop_count |
The number of stops from the departure to the arrival stop. This count includes the arrival stop, but excludes the departure stop. For example, if your route leaves from Stop A, passes through stops B and C, and arrives at stop D,
returns 3. |
trip_short_text |
The text that appears in schedules and sign boards to identify a transit trip to passengers. The text should uniquely identify a trip within a service day. For example, "538" is the |
TransitDetailsLocalizedValues
Localized descriptions of values for RouteTransitDetails
.
Fields | |
---|---|
arrival_time |
Time in its formatted text representation with a corresponding time zone. |
departure_time |
Time in its formatted text representation with a corresponding time zone. |
TransitStopDetails
Details about the transit stops for the RouteLegStep
.
Fields | |
---|---|
arrival_stop |
Information about the arrival stop for the step. |
arrival_time |
The estimated time of arrival for the step. |
departure_stop |
Information about the departure stop for the step. |
departure_time |
The estimated time of departure for the step. |
RouteLegStepTravelAdvisory
Contains the additional information that the user should be informed about, such as possible traffic zone restrictions on a leg step.
Fields | |
---|---|
speed_reading_intervals[] |
NOTE: This field is not currently populated. |
RouteLegTravelAdvisory
Contains the additional information that the user should be informed about on a leg step, such as possible traffic zone restrictions.
Fields | |
---|---|
toll_info |
Contains information about tolls on the specific |
speed_reading_intervals[] |
Speed reading intervals indicating traffic density. This field is only populated for requests when the request has a Example:
|
RouteMatrixDestination
A single destination for ComputeRouteMatrixRequest
Fields | |
---|---|
waypoint |
Required. Destination waypoint |
RouteMatrixElement
Contains route information computed for an origin/destination pair in the ComputeRouteMatrix API. This proto can be streamed to the client.
Fields | |
---|---|
status |
Error status code for this element. |
condition |
Indicates whether the route was found or not. Independent of status. |
distance_meters |
The travel distance of the route, in meters. |
duration |
The length of time needed to navigate the route. If you set the |
static_duration |
The duration of traveling through the route without taking traffic conditions into consideration. |
travel_advisory |
Additional information about the route. For example: restriction information and toll information |
fallback_info |
|