Route (beta) Stay organized with collections Save and categorize content based on your preferences.
Routeclass
google.maps.routes.Routeclass
Contains a route, which consists of a series of connected road segments that join beginning, ending, and intermediate waypoints.
Access by callingconst {Route} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Static Methods | |
|---|---|
computeRoutes | computeRoutes(request)Parameters:
Return Value: Promise<{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 request by setting the ComputeRoutesRequest.fields property. The value is a list of field paths.For example:
Use of the wildcard response field mask fields: ['*'] is discouraged because:
|
Properties | |
|---|---|
description | Type: stringoptionalA description of the route. |
distanceMeters | Type: numberoptionalThe travel distance of the route, in meters. |
durationMillis | Type: numberoptionalThe length of time needed to navigate the route in milliseconds. If you set ComputeRoutesRequest.routingPreference toTRAFFIC_UNAWARE, then this value is the same asRoute.staticDurationMillis. If you setComputeRoutesRequest.routingPreference to eitherTRAFFIC_AWARE orTRAFFIC_AWARE_OPTIMAL, then this value is calculated taking traffic conditions into account.Note: If the duration exceeds 2^53 milliseconds, then this value is Number.POSITIVE_INFINITY. |
legs | A collection of legs (path segments between waypoints) that make up the route. Each leg corresponds to the trip between two non- via waypoints.For example:
origin tointermediates todestination. |
localizedValues | Type: RouteLocalizedValuesoptionalText representations of properties of the Route. |
optimizedIntermediateWaypointIndices | Type: Array<number>optionalIf you set ComputeRoutesRequest.optimizeWaypointOrder totrue, this field contains the optimized ordering of intermediate waypoints. Otherwise, this field is empty. The index starts with 0 for the first intermediate waypoint provided in the input.For example, if you give an input of:
[2, 0, 1]. |
path | Type: Array<LatLngAltitude>optionalThe list of LatLngAltitudes of the route, which can be used to draw a route polyline. Granularity of the path can be controlled by settingComputeRoutesRequest.polylineQuality. |
polylineDetails | Type: PolylineDetailsoptionalContains information about details along the path. |
routeLabels | Type: Array<RouteLabel>optionalLabels for the route that are useful to identify specific properties of to compare against others. |
routeToken | Type: stringoptionalAn 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: routeToken is only available for requests that have setComputeRoutesRequest.routingPreference toTRAFFIC_AWARE orTRAFFIC_AWARE_OPTIMAL. It is not supported for requests that havevia waypoints. |
speedPaths | Groupings of sections of the route path with their corresponding speed reading. For this field to be populated, ComputeRoutesRequest.routingPreference must be set toTRAFFIC_AWARE orTRAFFIC_AWARE_OPTIMAL andComputeRoutesRequest.extraComputations must includeTRAFFIC_ON_POLYLINE. |
staticDurationMillis | Type: numberoptionalThe duration of traveling through the route without taking traffic conditions into consideration. Note: If the duration exceeds 2^53 milliseconds, then this value is Number.POSITIVE_INFINITY. |
travelAdvisory | Type: RouteTravelAdvisoryoptionalAdditional information about the route. |
viewport | Type: LatLngBoundsoptionalThe viewport bounding box of the route. |
warnings | Type: Array<string>optionalAn array of warnings to show when displaying the route. |
Methods | |
|---|---|
createPolylines | createPolylines([options])Parameters:
Creates polylines for the route based on the data available. Multi-modal polylines:
Traffic polylines:
Overall polyline:
|
createWaypointAdvancedMarkers | createWaypointAdvancedMarkers([options])Parameters:
Return Value: Promise<Array<AdvancedMarkerElement>>Creates markers for the route labeled 'A', 'B', 'C', etc. for each waypoint. Markers have default styling applied. Options can be passed in to alter the marker style based on the marker index or properties of the corresponding RouteLeg. TheWaypointMarkerDetails.leg parameter will be undefined if the route has no legs.The "legs" field must be requested inComputeRoutesRequest.fields in order for intermediate waypoints to be included. |
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
ComputeRoutesRequestinterface
google.maps.routes.ComputeRoutesRequestinterface
Request for routes.
Properties | |
|---|---|
destination | The destination of the route. A value passed as a string may be an address,plus code, or a Place resource name. Altitude values are not taken into consideration for computing routes. |
fields | Type: Iterable<string>Collection of fields to be fetched. Specify ["*"] for all fields. |
origin | The origin of the route. A value passed as a string may be an address,plus code, or a Place resource name. Altitude values are not taken into consideration for computing routes. |
arrivalTimeoptional | Type: DateoptionalThe arrival time. Note: Can only be set when ComputeRoutesRequest.travelMode is set toTRANSIT. You can specify eitherComputeRoutesRequest.departureTime orComputeRoutesRequest.arrivalTime, but not both. Transit trips are available for up to 7 days in the past or 100 days in the future. |
computeAlternativeRoutesoptional | Type: booleanoptionalSpecifies whether to calculate alternate routes in addition to the route. No alternative routes are returned for requests that have intermediate waypoints. |
departureTimeoptional | Type: DateoptionalThe 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 time in the past when ComputeRoutesRequest.travelMode is set toTRANSIT. Transit trips are available for up to 7 days in the past or 100 days in the future. |
extraComputationsoptional | Type: Iterable<ComputeRoutesExtraComputation>optionalA 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 ComputeRoutesRequest.fields to be returned in the response. |
intermediatesoptional | A set of waypoints along the route (excluding terminal points), for either stopping at or passing by. Up to 25 intermediate waypoints are supported. |
languageoptional | Type: stringoptionalThe BCP-47 language code, such as "en-US" or "sr-Latn". For more information, seeUnicode Locale Identifier. SeeLanguage Support for the list of supported languages. When you don't provide this value, the language is inferred from your Google Maps JavaScript APIlocalization settings. Otherwise, the language is inferred from the location of the origin. |
optimizeWaypointOrderoptional | Type: booleanoptionalIf 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 via waypoint. Use Route.optimizedIntermediateWaypointIndices in the response to find the new ordering. If"optimizedIntermediateWaypointIndices" is not requested inComputeRoutesRequest.fields, the request fails. If set to false,Route.optimizedIntermediateWaypointIndices in the response will be empty. |
polylineQualityoptional | Type: PolylineQualityoptionalSpecifies the preference for the quality of the polyline. |
regionoptional | Type: stringoptionalThe region code, specified as a ccTLD ("top-level domain") two-character value. For more information seeCountry code top-level domains. When you don't provide this value, the region is inferred from your Google Maps JavaScript APIlocalization settings. Otherwise, the region is inferred from the location of the origin. |
requestedReferenceRoutesoptional | Type: Iterable<ReferenceRoute>optionalSpecifies 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 FUEL_EFFICIENT reference route calculation takes into account various parameters that would generate an optimal fuel efficient route. When using this feature, look forRoute.routeLabels on the resulting routes. |
routeModifiersoptional | Type: RouteModifiersoptionalA set of conditions to satisfy that affect the way routes are calculated. For example you can specify features to avoid such as toll roads or highways. |
routingPreferenceoptional | Type: RoutingPreferenceoptionalSpecifies 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 ComputeRoutesRequest.travelMode isDRIVING orTWO_WHEELER, otherwise the request fails. |
trafficModeloptional | Type: TrafficModeloptionalSpecifies the assumptions to use when calculating time in traffic. This setting affects the value of Route.durationMillis andRouteLeg.durationMillis which contain the predicted time in traffic based on historical averages.ComputeRoutesRequest.trafficModel is only available for requests that have setComputeRoutesRequest.routingPreference toTRAFFIC_AWARE_OPTIMAL andComputeRoutesRequest.travelMode toDRIVING. Defaults toBEST_GUESS. |
transitPreferenceoptional | Type: TransitPreferenceoptionalSpecifies preferences that influence the route returned for TRANSIT routes.Note: Can only be specified when ComputeRoutesRequest.travelMode is set toTRANSIT. |
travelModeoptional | Type: TravelModeoptionalSpecifies the mode of transportation. |
unitsoptional | Type: UnitSystemoptionalSpecifies the units of measure for the display fields, such as navigation instructions. The units of measure used for the route, leg, step distance, and duration are not affected by this value. If you don't provide this value, then the display units are inferred from the location of the origin. |
ComputeRoutesExtraComputationconstants
google.maps.routes.ComputeRoutesExtraComputationconstants
Extra computations to perform for aRoute.computeRoutes request.
Access by callingconst {ComputeRoutesExtraComputation} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Constants | |
|---|---|
FLYOVER_INFO_ON_POLYLINE | Flyover information for the route(s). The"polylineDetails" field must be specified inComputeRoutesRequest.fields 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. |
FUEL_CONSUMPTION | Estimated fuel consumption for the route(s). |
HTML_FORMATTED_NAVIGATION_INSTRUCTIONS | Navigation instructions presented as a formatted HTML text string. This content is meant to be read as-is and is for display only. Do not programmatically parse it. |
NARROW_ROAD_INFO_ON_POLYLINE | Narrow road information for the route(s). The"polylineDetails" field must be specified inComputeRoutesRequest.fields 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. |
TOLLS | Toll information for the route(s). |
TRAFFIC_ON_POLYLINE | Traffic aware polylines for the route(s). |
DirectionalLocationLiteralinterface
google.maps.routes.DirectionalLocationLiteralinterface
Object literals are accepted in place ofDirectionalLocation instances as a convenience. These are converted toDirectionalLocation when the Maps JS API encounters them.
This interface extendsLatLngAltitudeLiteral.
Properties | |
|---|---|
headingoptional | Type: numberoptionalThe compass heading associated with the direction of the flow of traffic. Heading values can be numbers 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 DRIVING andTWO_WHEELERComputeRoutesRequest.travelMode. |
Inherited:altitude,lat,lng | |
DirectionalLocationclass
google.maps.routes.DirectionalLocationclass
Encapsulates a geographic point and an optional heading.
This class extendsLatLngAltitude.
This class implementsDirectionalLocationLiteral.
Access by callingconst {DirectionalLocation} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Constructor | |
|---|---|
Inherited:LatLngAltitude |
Properties | |
|---|---|
heading | Type: numberoptionalThe compass heading associated with the direction of the flow of traffic. Heading values can be numbers 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 DRIVING andTWO_WHEELERComputeRoutesRequest.travelMode. |
Inherited:altitude,lat,lng | |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: DirectionalLocationLiteralConverts to an object. |
Inherited:equals | |
FallbackInfoclass
google.maps.routes.FallbackInfoclass
Information related to how and why a fallback result was used in aRoute.computeRoutes response. If this field is set, then it means the server used a different routing mode from your preferred mode as fallback.
Access by callingconst {FallbackInfo} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
reason | Type: FallbackReasonoptionalThe 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. |
routingMode | Type: FallbackRoutingModeoptionalRouting mode used for the response. If fallback was triggered, the mode may be different from routing preference set in the original client request. |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
FallbackReasonconstants
google.maps.routes.FallbackReasonconstants
The reason that a fallback response was returned in aRoute.computeRoutes response.
Access by callingconst {FallbackReason} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Constants | |
|---|---|
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. |
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. |
FallbackRoutingModeconstants
google.maps.routes.FallbackRoutingModeconstants
The actual routing mode used when a fallback response is returned in aRoute.computeRoutes response.
Access by callingconst {FallbackRoutingMode} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Constants | |
|---|---|
TRAFFIC_AWARE | Indicates theTRAFFIC_AWARERoutingPreference was used to compute the response. |
TRAFFIC_UNAWARE | Indicates theTRAFFIC_UNAWARERoutingPreference was used to compute the response. |
GeocodedWaypointclass
google.maps.routes.GeocodedWaypointclass
Geocoding 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.
Access by callingconst {GeocodedWaypoint} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
geocoderStatus | Type: RPCStatusoptionalIndicates the status code resulting from the geocoding operation. |
intermediateWaypointRequestIndex | Type: numberoptionalThe index of the corresponding intermediate waypoint in the request. Only populated if the corresponding waypoint is an intermediate waypoint. |
partialMatch | Type: booleanIndicates 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. |
placeId | Type: stringThe place ID for this result. |
types | Type: Array<string>The type(s) of the result, in the form of zero or more type tags. Seehttps://developers.google.com/maps/documentation/geocoding/requests-geocoding#Types for supported types. |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
GeocodingResultsclass
google.maps.routes.GeocodingResultsclass
ContainsGeocodedWaypoints for origin, destination, and intermediate waypoints. Only populated for address waypoints.
Access by callingconst {GeocodingResults} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
destination | Type: GeocodedWaypointoptionalThe geocoded waypoint for the destination. |
intermediates | Type: Array<GeocodedWaypoint>optionalA 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. |
origin | Type: GeocodedWaypointoptionalThe geocoded waypoint for the origin. |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
MultiModalSegmentclass
google.maps.routes.MultiModalSegmentclass
Provides summarized information about a multi-modal segment of theRouteLeg.steps of a route. A multi-modal segment is defined as one or more contiguousRouteLegStep's that have the sameTravelMode.
Access by callingconst {MultiModalSegment} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
instructions | Type: stringoptionalInstructions for navigating this multi-modal segment. |
maneuver | Type: stringoptionalThe navigation maneuver to perform at this step. SeeManeuver for a list of possible values. |
stepEndIndex | Type: numberThe corresponding RouteLegStep index that is the end of a multi-modal segment. |
stepStartIndex | Type: numberThe corresponding RouteLegStep index that is the start of a multi-modal segment. |
travelMode | Type: TravelModeoptionalThe travel mode used for this multi-modal segment. |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
PolylineDetailInfoclass
google.maps.routes.PolylineDetailInfoclass
Encapsulates information about a road feature along a stretch of polyline.
Access by callingconst {PolylineDetailInfo} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
endIndex | Type: numberoptionalThe end index of this road feature in the polyline. |
presence | Type: RoadFeatureStateoptionalDenotes whether the road feature exists along the polyline. |
startIndex | Type: numberoptionalThe start index of this road feature in the polyline. |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
PolylineDetailsclass
google.maps.routes.PolylineDetailsclass
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), thePolylineDetails describes a road feature for a given interval.
Access by callingconst {PolylineDetails} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
flyoverInfo | Type: Array<PolylineDetailInfo>Flyover details along the polyline. |
narrowRoadInfo | Type: Array<PolylineDetailInfo>Narrow road details along the polyline. |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
PolylineQualityconstants
google.maps.routes.PolylineQualityconstants
Specifies the quality of the polyline.
Access by callingconst {PolylineQuality} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Constants | |
|---|---|
HIGH_QUALITY | Specifies a high-quality polyline that is composed using more points thanOVERVIEW at the cost of increased response size. Use this value when you need more precision. |
OVERVIEW | Specifies an overview polyline that is composed using a small number of points. Using this option has a lower request latency compared toHIGH_QUALITY. Use this value when displaying an overview of the route. |
ReferenceRouteconstants
google.maps.routes.ReferenceRouteconstants
A supported reference route on aComputeRoutesRequest.
Access by callingconst {ReferenceRoute} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Constants | |
|---|---|
FUEL_EFFICIENT | Fuel efficient route. |
SHORTER_DISTANCE | Route with shorter travel distance. |
RoadFeatureStateconstants
google.maps.routes.RoadFeatureStateconstants
Encapsulates the states of road features along a stretch of polyline.
Access by callingconst {RoadFeatureState} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Constants | |
|---|---|
DOES_NOT_EXIST | The road feature does not exist. |
EXISTS | The road feature exists. |
RouteLabelconstants
google.maps.routes.RouteLabelconstants
Labels for the route that are useful to identify specific properties to compare against others.
Access by callingconst {RouteLabel} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Constants | |
|---|---|
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 whenComputeRoutesRequest.computeAlternativeRoutes 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. |
RouteLegclass
google.maps.routes.RouteLegclass
Contains a segment between non-via waypoints.
Access by callingconst {RouteLeg} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
distanceMeters | Type: numberThe travel distance of the route leg, in meters. |
durationMillis | Type: numberoptionalThe length of time needed to navigate the route leg in milliseconds. If you set ComputeRoutesRequest.routingPreference toTRAFFIC_UNAWARE, then this value is the same asstaticDurationMillis. If you setComputeRoutesRequest.routingPreference to eitherTRAFFIC_AWARE orTRAFFIC_AWARE_OPTIMAL, then this value is calculated taking traffic conditions into account.Note: If the duration exceeds 2^53 milliseconds, then this value is Number.POSITIVE_INFINITY. |
endLocation | Type: DirectionalLocationoptionalThe end location of this leg. This location might be different from ComputeRoutesRequest.destination. For example, whenComputeRoutesRequest.destination is not near a road, this is a point on the road. |
localizedValues | Type: RouteLegLocalizedValuesoptionalText representations of properties of the RouteLeg. |
path | Type: Array<LatLngAltitude>The list of LatLngAltitudes of the route leg, which can be used to draw a route leg polyline. Granularity of the path can be controlled by settingComputeRoutesRequest.polylineQuality. |
speedPaths | Groupings of sections of the route leg path with their corresponding speed reading. For this field to be populated, ComputeRoutesRequest.routingPreference must be set toTRAFFIC_AWARE orTRAFFIC_AWARE_OPTIMAL andComputeRoutesRequest.extraComputations must includeTRAFFIC_ON_POLYLINE. |
startLocation | Type: DirectionalLocationoptionalThe start location of this leg. This location might be different from ComputeRoutesRequest.origin. For example, whenComputeRoutesRequest.origin is not near a road, this is a point on the road. |
staticDurationMillis | Type: numberoptionalThe duration of traveling through the leg without taking traffic conditions into consideration. Note: If the duration exceeds 2^53 milliseconds, then this value is Number.POSITIVE_INFINITY. |
steps | Type: Array<RouteLegStep>An array of steps denoting segments within this leg. Each step represents one navigation instruction. |
stepsOverview | Type: StepsOverviewoptionalOverview information about the steps in this RouteLeg. This field is only populated forTRANSIT routes. |
travelAdvisory | Type: RouteLegTravelAdvisoryoptionalContains the additional information that the user should be informed about, such as possible traffic zone restrictions, on a route leg. |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
RouteLegLocalizedValuesclass
google.maps.routes.RouteLegLocalizedValuesclass
Text representations of theRouteLeg.
Access by callingconst {RouteLegLocalizedValues} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
distance | Type: stringoptionalTravel distance of the route leg in text form. |
distanceLanguage | Type: stringoptionalThe distance text's BCP-47 language code, such as "en-US" or "sr-Latn". For more information, seehttp://www.unicode.org/reports/tr35/#Unicode_locale_identifier. |
duration | Type: stringoptionalDuration, represented in text form and localized to the region of the query. Takes traffic conditions into consideration. |
durationLanguage | Type: stringoptionalThe duration text's BCP-47 language code, such as "en-US" or "sr-Latn". For more information, seehttp://www.unicode.org/reports/tr35/#Unicode_locale_identifier. |
staticDuration | Type: stringoptionalDuration without taking traffic conditions into consideration, represented in text form. |
staticDurationLanguage | Type: stringoptionalThe static duration text's BCP-47 language code, such as "en-US" or "sr-Latn". |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
RouteLegStepclass
google.maps.routes.RouteLegStepclass
Contains a segment of aRouteLeg. A step corresponds to a single navigation instruction. Route legs are made up of steps.
Access by callingconst {RouteLegStep} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
distanceMeters | Type: numberThe travel distance of this step, in meters. |
endLocation | Type: DirectionalLocationoptionalThe end location of this step. |
instructions | Type: stringoptionalInstructions for navigating this step. |
localizedValues | Type: RouteLegStepLocalizedValuesoptionalText representations of properties of the RouteLegStep. |
maneuver | Type: stringoptionalThe navigation maneuver to perform at this step. SeeManeuver for a list of possible values. |
path | Type: Array<LatLngAltitude>The list of LatLngAltitudes of the route leg step, which can be used to draw a route leg step polyline. Granularity of the path can be controlled by settingComputeRoutesRequest.polylineQuality. The"path" field must be requested inComputeRoutesRequest.fields in order for this field to be populated. |
startLocation | Type: DirectionalLocationoptionalThe start location of this step. |
staticDurationMillis | Type: numberoptionalThe duration of traveling through this step without taking traffic conditions into consideration. Note: If the duration exceeds 2^53 milliseconds, then this value is Number.POSITIVE_INFINITY. |
transitDetails | Type: TransitDetailsoptionalDetails pertaining to this step if the travel mode is TRANSIT. |
travelMode | Type: TravelModeoptionalThe travel mode used for this step. |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
RouteLegStepLocalizedValuesclass
google.maps.routes.RouteLegStepLocalizedValuesclass
Text representations of properties of theRouteLegStep.
Access by callingconst {RouteLegStepLocalizedValues} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
distance | Type: stringoptionalTravel distance of the route leg step in text form. |
distanceLanguage | Type: stringoptionalThe distance text's BCP-47 language code, such as "en-US" or "sr-Latn". For more information, seehttp://www.unicode.org/reports/tr35/#Unicode_locale_identifier. |
staticDuration | Type: stringoptionalDuration without taking traffic conditions into consideration, represented in text form. |
staticDurationLanguage | Type: stringoptionalThe static duration text's BCP-47 language code, such as "en-US" or "sr-Latn". For more information, seehttp://www.unicode.org/reports/tr35/#Unicode_locale_identifier. |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
RouteLegTravelAdvisoryclass
google.maps.routes.RouteLegTravelAdvisoryclass
Contains additional information that the user should be informed about on aRouteLeg.
Access by callingconst {RouteLegTravelAdvisory} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
speedReadingIntervals | Type: Array<SpeedReadingInterval>optionalSpeed reading intervals detailing traffic density. Applicable in case of TRAFFIC_AWARE andTRAFFIC_AWARE_OPTIMALComputeRoutesRequest.routingPreference. The intervals cover the entire polyline of theRouteLeg without overlap. The start point of a specified interval is the same as the end point of the preceding interval.Example: |
tollInfo | Type: TollInfooptionalContains information about tolls on the specific RouteLeg. This field is only populated if tolls are expected on theRouteLeg. If this field is set butTollInfo.estimatedPrices is not populated,then the route leg contains tolls but the estimated price is unknown. If this field is empty, then there are no tolls on theRouteLeg. |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
RouteLocalizedValuesclass
google.maps.routes.RouteLocalizedValuesclass
Text representations of properties of theRoute.
Access by callingconst {RouteLocalizedValues} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
distance | Type: stringoptionalTravel distance of the route represented in text form. |
distanceLanguage | Type: stringoptionalThe distance text's BCP-47 language code, such as "en-US" or "sr-Latn". For more information, seehttp://www.unicode.org/reports/tr35/#Unicode_locale_identifier. |
duration | Type: stringoptionalDuration, 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 staticDuration. |
durationLanguage | Type: stringoptionalThe duration text's BCP-47 language code, such as "en-US" or "sr-Latn". For more information, seehttp://www.unicode.org/reports/tr35/#Unicode_locale_identifier. |
staticDuration | Type: stringoptionalDuration without taking traffic conditions into consideration, represented in text form. |
staticDurationLanguage | Type: stringoptionalThe static duration text's BCP-47 language code, such as "en-US" or "sr-Latn". |
transitFare | Type: stringoptionalTransit fare represented in text form. |
transitFareLanguage | Type: stringoptionalThe transit fare text's BCP-47 language code, such as "en-US" or "sr-Latn". |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
RouteModifiersinterface
google.maps.routes.RouteModifiersinterface
Encapsulates a set of optional conditions to satisfy when calculating routes.
Properties | |
|---|---|
avoidFerriesoptional | Type: booleanoptionalWhen set to true, avoids ferries where reasonable, giving preference to routes not containing ferries. Applies only toDRIVING orTWO_WHEELERTravelMode. |
avoidHighwaysoptional | Type: booleanoptionalWhen set to true, avoids highways where reasonable, giving preference to routes not containing highways. Applies only toDRIVING orTWO_WHEELERTravelMode. |
avoidIndooroptional | Type: booleanoptionalWhen set to true, avoids navigating indoors where reasonable, giving preference to routes not containing indoor navigation. Applies only toWALKINGTravelMode. |
avoidTollsoptional | Type: booleanoptionalWhen set to true, avoids toll roads where reasonable, giving preference to routes not containing toll roads. Applies only toDRIVING orTWO_WHEELERTravelMode. |
tollPassesoptional | Type: Iterable<string>optionalEncapsulates information about toll passes. If toll passes are provided, the API tries to return the pass price. If toll passes are not provided, the API treats the toll pass as unknown and tries to return the cash price. Applies only to DRIVING orTWO_WHEELERTravelMode. SeeTollPass for a list of valid values. |
vehicleInfooptional | Type: VehicleInfooptionalSpecifies the vehicle information. |
RoutePolylineDetailsinterface
google.maps.routes.RoutePolylineDetailsinterface
Details about a section of a route corresponding to a polyline that can be used to customize the polyline style.
Properties | |
|---|---|
speedoptional | Type: SpeedoptionalThe speed reading of the section of the route corresponding to this polyline. Only populated for routes with traffic information. |
transitDetailsoptional | Type: TransitDetailsoptionalThe transit details of the section of the route corresponding to this polyline. Only populated for routes with transit information. |
travelModeoptional | Type: TravelModeoptionalThe travel mode of the section of the route corresponding to this polyline. Empty for traffic polylines. |
RoutePolylineOptionsinterface
google.maps.routes.RoutePolylineOptionsinterface
Options for creating route polylines.
Properties | |
|---|---|
colorSchemeoptional | Type: ColorSchemeoptionalThe color scheme to use for the polyline. When specified as FOLLOW_SYSTEM while the mapcolorScheme is alsoFOLLOW_SYSTEM, the polylines will be drawn in the same dark/light mode as the map. When not specified,Route.createPolylines attempts to use thecolorScheme of the map or falls back to the system default. |
polylineOptionsoptional | Type: PolylineOptions|(function(PolylineOptions,RoutePolylineDetails):PolylineOptions)optionalOptions for customizing the style of a polyline. Can either be a PolylineOptions object that is applied to all polylines for the route or a function that takes defaultPolylineOptions andRoutePolylineDetails and returns thePolylineOptions to be applied to that polyline. |
RouteTravelAdvisoryclass
google.maps.routes.RouteTravelAdvisoryclass
Contains additional information that the user should be informed about on aRoute.
Access by callingconst {RouteTravelAdvisory} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
fuelConsumptionMicroliters | Type: numberoptionalThe predicted fuel consumption in microliters. Note: If the fuel consumption exceeds 2^53 microliters, then this value is Number.POSITIVE_INFINITY. |
routeRestrictionsPartiallyIgnored | Type: booleanoptionalThe Route may have restrictions that are not suitable for the requested travel mode or route modifiers. |
speedReadingIntervals | Type: Array<SpeedReadingInterval>optionalSpeed reading intervals detailing traffic density. Applicable in case of TRAFFIC_AWARE andTRAFFIC_AWARE_OPTIMALComputeRoutesRequest.routingPreference. The intervals cover the entire polyline of theRoute without overlap. The start point of a specified interval is the same as the end point of the preceding interval.Example: |
tollInfo | Type: TollInfooptionalContains information about tolls on the Route. This field is only populated if tolls are expected on theRoute. If this field is set butTollInfo.estimatedPrices is not populated,then the route contains tolls but the estimated price is unknown. If this field is empty, then there are no tolls on theRoute. |
transitFare | Type: MoneyoptionalIf present, contains the total fare or ticket costs of this Route. This property is only returned forTRANSITComputeRoutesRequest.travelMode and only for routes where fare information is available for all transit steps. |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
RoutingPreferenceconstants
google.maps.routes.RoutingPreferenceconstants
Factors to take into consideration when calculating a route.
Access by callingconst {RoutingPreference} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Constants | |
|---|---|
TRAFFIC_AWARE | Calculates routes taking live traffic conditions into consideration. In contrast toTRAFFIC_AWARE_OPTIMAL, some optimizations are applied to significantly reduce latency. |
TRAFFIC_AWARE_OPTIMAL | Calculates the routes taking live traffic conditions into consideration, without applying most performance optimizations. Using this value produces the highest latency. |
TRAFFIC_UNAWARE | Computes routes without taking live traffic conditions into consideration. Suitable when traffic conditions don't matter or are not applicable. Using this value produces the lowest latency. |
Speedconstants
google.maps.routes.Speedconstants
The classification of polyline speed based on traffic data.
Access by callingconst {Speed} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Constants | |
|---|---|
NORMAL | Normal speed, no traffic delays. |
SLOW | Slowdown detected, medium amount of traffic. |
TRAFFIC_JAM | Traffic delays. |
SpeedPathinterface
google.maps.routes.SpeedPathinterface
Groups together theLatLngAltitudes of a route interval with the speed reading for the interval.
Properties | |
|---|---|
path | Type: Array<LatLngAltitude>The path covered by this speed path. |
speedoptional | Type: SpeedoptionalThe speed reading of the path. |
SpeedReadingIntervalclass
google.maps.routes.SpeedReadingIntervalclass
Traffic density indicator on a contiguous segment of a polyline or path. Given a path with points P_0, P_1, ... , P_N (zero-based index), theSpeedReadingInterval describes the traffic density of an interval.
Access by callingconst {SpeedReadingInterval} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
endPolylinePointIndex | Type: numberoptionalThe ending index of this interval in the polyline. |
speed | Type: SpeedoptionalTraffic speed in this interval. |
startPolylinePointIndex | Type: numberoptionalThe starting index of this interval in the polyline. |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: None Converts to an object. |
StepsOverviewclass
google.maps.routes.StepsOverviewclass
Provides overview information about a list ofRouteLeg.steps.
Access by callingconst {StepsOverview} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
multiModalSegments | Type: Array<MultiModalSegment>Summarized information about different multi-modal segments of the RouteLeg.steps. |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
TollInfoclass
google.maps.routes.TollInfoclass
Encapsulates toll information on aRoute orRouteLeg.
Access by callingconst {TollInfo} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
estimatedPrices | The monetary amount of tolls for the corresponding Route orRouteLeg. This list contains an amount for each currency that is expected to be charged by toll stations. Typically this list will contain only one item for routes with tolls in one currency. For international trips, this list may contain multiple items to reflect tolls in different currencies. |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
TransitAgencyclass
google.maps.routes.TransitAgencyclass
Information about a transit agency.
Access by callingconst {TransitAgency} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
name | Type: stringoptionalThe name of this transit agency. |
phoneNumber | Type: stringoptionalThe transit agency's locale-specific formatted phone number. |
url | Type: URLoptionalThe transit agency's URL. |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
TransitDetailsclass
google.maps.routes.TransitDetailsclass
Additional information about a transit step in a route.
Access by callingconst {TransitDetails} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
arrivalStop | Type: TransitStopoptionalInformation about the arrival stop for the step. |
arrivalTime | Type: DateoptionalThe estimated time of arrival for the step. |
departureStop | Type: TransitStopoptionalInformation about the departure stop for the step. |
departureTime | Type: DateoptionalThe estimated time of departure for the step. |
headsign | Type: stringoptionalSpecifies 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. |
headwayMillis | Type: numberoptionalSpecifies the expected time in milliseconds between departures from the same stop at this time. For example, with a headway value of 600,000, you would expect a ten minute wait if you should miss your bus. Note: If the headway exceeds 2^53 milliseconds, then this value is Number.POSITIVE_INFINITY. |
stopCount | Type: numberThe 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, stopCount will be 3. |
transitLine | Type: TransitLineoptionalInformation about the transit line used in the step. |
tripShortText | Type: stringoptionalThe text that appears in schedules and sign boards to identify a transit trip to passengers. The text uniquely identifies a trip within a service day. For example, "538" is the tripShortText of the Amtrak train that leaves San Jose, CA at 15:10 on weekdays to Sacramento, CA. |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
TransitLineclass
google.maps.routes.TransitLineclass
Information about a transit line.
Access by callingconst {TransitLine} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
agencies | Type: Array<TransitAgency>The transit agency (or agencies) that operates this transit line. |
color | Type: stringoptionalThe color commonly used in signage for this line. Represented in hexadecimal. |
iconURL | Type: URLoptionalThe URL for the icon associated with this line. |
name | Type: stringoptionalThe full name of this transit line, For example, "8 Avenue Local". |
shortName | Type: stringoptionalThe short name of this transit line. This name will normally be a line number, such as "M7" or "355". |
textColor | Type: stringoptionalThe color commonly used in text on signage for this line. Represented in hexadecimal. |
url | Type: URLoptionalThe URL for this transit line as provided by the transit agency. |
vehicle | Type: TransitVehicleoptionalThe type of vehicle that operates on this transit line. |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
TransitPreferenceinterface
google.maps.routes.TransitPreferenceinterface
Preferences forTRANSIT based routes that influence the route that is returned.
Properties | |
|---|---|
allowedTransitModesoptional | Type: Iterable<TransitMode>optionalA set of travel modes to use when getting a TRANSIT route. Defaults to all supported modes of travel. |
routingPreferenceoptional | Type: TransitRoutePreferenceoptionalA routing preference that, when specified, influences the TRANSIT route returned. |
TransitStopclass
google.maps.routes.TransitStopclass
Information about a transit stop.
Access by callingconst {TransitStop} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
location | Type: DirectionalLocationoptionalThe location of the stop expressed in latitude/longitude coordinates and an optional heading. |
name | Type: stringoptionalThe name of the transit stop. |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
TransitVehicleclass
google.maps.routes.TransitVehicleclass
Information about a vehicle used in transit routes.
Access by callingconst {TransitVehicle} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Properties | |
|---|---|
iconURL | Type: URLoptionalThe URL for an icon associated with this vehicle type. |
localIconURL | Type: URLoptionalThe URL for the icon associated with this vehicle type, based on the local transport signage. |
name | Type: stringoptionalThe name of this vehicle, capitalized. |
nameLanguage | Type: stringoptionalThe vehicle name text's BCP-47 language code, such as "en-US" or "sr-Latn". For more information see:https://www.unicode.org/reports/tr35/#Unicode_locale_identifier. |
vehicleType | Type: stringoptionalThe type of vehicle used. Seehttps://developers.google.com/maps/documentation/routes/reference/rpc/google.maps.routing.v2#transitvehicletype for a list of possible values. |
Methods | |
|---|---|
toJSON | toJSON()Parameters: None Return Value: ObjectConverts to an object. |
VehicleEmissionTypeconstants
google.maps.routes.VehicleEmissionTypeconstants
A set of values describing the vehicle's emission type. Applies only to theDRIVING travel mode.
Access by callingconst {VehicleEmissionType} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.
Constants | |
|---|---|
DIESEL | Diesel fueled vehicle. |
ELECTRIC | Electricity powered vehicle. |
GASOLINE | Gasoline/petrol fueled vehicle. |
HYBRID | Hybrid fuel (such as gasoline + electric) vehicle. |
VehicleInfointerface
google.maps.routes.VehicleInfointerface
Contains the vehicle information, such as the vehicle emission type.
Properties | |
|---|---|
emissionTypeoptional | Type: VehicleEmissionTypeoptionalDescribes the vehicle's emission type. Applies only to the DRIVING travel mode. |
Waypointinterface
google.maps.routes.Waypointinterface
Represents a waypoint in a route.
Properties | |
|---|---|
location | The location of the waypoint. A string may be an address, aplus code, or a Place resource name. |
sideOfRoadoptional | Type: booleanoptionalIndicates that the location of this waypoint is meant to have a preference for the vehicle to stop at a particular side of road. When you set this value, the route will pass through the location so that the vehicle can stop at the side of road that the location is biased towards from the center of the road. This option works only for DRIVING andTWO_WHEELERComputeRoutesRequest.travelMode |
vehicleStopoveroptional | Type: booleanoptionalIndicates that the waypoint is meant for vehicles to stop at, where the intention is to either pickup or drop-off. When you set this value, the calculated route won't include non- via waypoints on roads that are unsuitable for pickup and drop-off. This option works only forDRIVING andTWO_WHEELERComputeRoutesRequest.travelMode and when theWaypoint.location is not astring or aPlace. |
viaoptional | Type: booleanoptionalMarks this waypoint as a milestone rather a stopping point. For each non- via waypoint in theComputeRoutesRequest,Route.computeRoutes appends an entry to theRoute.legs array to provide the details for stopovers on that leg of the trip.Set this value to true when you want the route to pass through this waypoint without stopping over. Via waypoints don't cause an entry to be added to theRoute.legs array, but they do route the journey through the waypoint.Notes:
|
WaypointMarkerDetailsinterface
google.maps.routes.WaypointMarkerDetailsinterface
Details about a waypoint that can be used to customize marker style.
Properties | |
|---|---|
index | Type: numberThe index of the marker. |
totalMarkers | Type: numberThe total number of markers in the route. |
legoptional | Type: RouteLegoptionalThe leg that the marker belongs to. Empty if the route has no legs. |
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-11-06 UTC.