RouteMatrix class
google.maps.routes.RouteMatrix
class
A matrix of routes computed for a set of origin/destination pairs by RouteMatrix.computeRouteMatrix
Access by calling const {RouteMatrix} = await google.maps.importLibrary("routes")
.
See Libraries in the Maps JavaScript API.
Static Methods | |
---|---|
computeRouteMatrix |
computeRouteMatrix(request) Parameters:
Return Value:
Promise<{matrix:RouteMatrix}> Takes in a list of origins and destinations and returns a matrix containing route information for each combination of origin and destination. Note: This method requires that you specify a response field mask in the request by setting the ComputeRouteMatrixRequest.fields property. The value is a list of field paths. For example:
Use of the wildcard response field mask fields: ['*'] is discouraged because:
|
Properties | |
---|---|
rows |
Type:
Array<RouteMatrixRow> The rows of the matrix. Each row corresponds to an origin and contains an array of RouteMatrixItem s, each representing a route to a destination. |
Methods | |
---|---|
toJSON |
toJSON() Parameters: None
Return Value:
Object Converts to an object. |
RouteMatrixRow class
google.maps.routes.RouteMatrixRow
class
Corresponds to an origin passed to RouteMatrix.computeRouteMatrix
. Contains a list of RouteMatrixItem
s, each item representing a route to a destination.
Access by calling const {RouteMatrixRow} = await google.maps.importLibrary("routes")
.
See Libraries in the Maps JavaScript API.
Properties | |
---|---|
items |
Type:
Array<RouteMatrixItem> The route information for each destination. |
Methods | |
---|---|
toJSON |
toJSON() Parameters: None
Return Value:
Object Converts to an object. |
RouteMatrixItem class
google.maps.routes.RouteMatrixItem
class
Contains route information computed for an origin/destination pair passed to RouteMatrix.computeRouteMatrix
.
Access by calling const {RouteMatrixItem} = await google.maps.importLibrary("routes")
.
See Libraries in the Maps JavaScript API.
Properties | |
---|---|
condition |
Type:
RouteMatrixItemCondition optional Indicates whether the route was found or not. |
distanceMeters |
Type:
number optional The travel distance of the route in meters. |
durationMillis |
Type:
number optional The length of time needed to navigate the route in milliseconds. If you set ComputeRouteMatrixRequest.routingPreference to TRAFFIC_UNAWARE , then this value is the same as RouteMatrixItem.staticDurationMillis . If you set ComputeRouteMatrixRequest.routingPreference to either TRAFFIC_AWARE or TRAFFIC_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 . |
error |
Type:
RouteMatrixItemError optional Error that occurred during the computation of the route. |
fallbackInfo |
Type:
FallbackInfo optional 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 a fallback is used, this field contains detailed information about the fallback response. Otherwise this field is unset. |
localizedValues |
Type:
RouteMatrixItemLocalizedValues optional Text representations of properties of the RouteMatrixItem . |
staticDurationMillis |
Type:
number optional The 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:
RouteTravelAdvisory optional Additional information about the route. |
ComputeRouteMatrixRequest interface
google.maps.routes.ComputeRouteMatrixRequest
interface
Request for a route matrix.
Properties | |
---|---|
destinations |
Type:
Iterable<string|LatLng|LatLngLiteral|LatLngAltitudeLiteral|DirectionalLocationLiteral|Place|Waypoint> Array of destinations, which determines the columns of the response matrix. A value passed as a string may be an address or plus code. Altitude values are not taken into consideration. |
fields |
Type:
Iterable<string> Collection of fields to be fetched. Specify ["*"] for all fields. |
origins |
Type:
Iterable<string|LatLng|LatLngLiteral|LatLngAltitudeLiteral|DirectionalLocationLiteral|Place|RouteMatrixOrigin|Waypoint> Array of origins, which determines the rows of the response matrix. A value passed as a string may be an address or plus code. Altitude values are not taken into consideration. Several size restrictions apply to the cardinality of origins and destinations:
|
arrivalTime optional |
Type:
Date optional The arrival time. Note: Can only be set when ComputeRouteMatrixRequest.travelMode is set to TRANSIT . You can specify either ComputeRouteMatrixRequest.departureTime or ComputeRouteMatrixRequest.arrivalTime , but not both. Transit trips are available for up to 7 days in the past or 100 days in the future. |
departureTime optional |
Type:
Date 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 time in the past when ComputeRouteMatrixRequest.travelMode is set to TRANSIT . Transit trips are available for up to 7 days in the past or 100 days in the future. |
extraComputations optional |
Type:
Iterable<ComputeRouteMatrixExtraComputation> 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 ComputeRouteMatrixRequest.fields to be returned in the response. |
language optional |
Type:
string 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 language is inferred from your Google Maps JavaScript API localization settings. Otherwise, the language is inferred from the location of the first origin. |
region optional |
Type:
string optional The region code, specified as a ccTLD ("top-level domain") two-character value. For more information see Country code top-level domains. When you don't provide this value, the region is inferred from your Google Maps JavaScript API localization settings. Otherwise, the region is inferred from the location of the first origin. |
routingPreference optional |
Type:
RoutingPreference optional Specifies how to compute the route matrix. The server attempts to use the selected routing preference to compute the route matrix. If the routing preference results in an error or an extra long latency, an error is returned. You can specify this option only when ComputeRouteMatrixRequest.travelMode is DRIVING or TWO_WHEELER , otherwise the request fails. |
trafficModel optional |
Type:
TrafficModel optional Specifies the assumptions to use when calculating time in traffic. This setting affects the value returned in RouteMatrixItem.durationMillis which contains the predicted time in traffic based on historical averages. ComputeRouteMatrixRequest.trafficModel is only available for requests that have set ComputeRouteMatrixRequest.routingPreference to TRAFFIC_AWARE_OPTIMAL and ComputeRouteMatrixRequest.travelMode to DRIVING . Defaults to BEST_GUESS . |
transitPreference optional |
Type:
TransitPreference optional Specifies preferences that influence the route returned for TRANSIT routes. Note: Can only be specified when ComputeRouteMatrixRequest.travelMode is set to TRANSIT . |
travelMode optional |
Type:
TravelMode optional Specifies the mode of transportation. |
units optional |
Type:
UnitSystem optional Specifies the units of measure for the display fields. If you don't provide this value, then the display units are inferred from the location of the first origin. |
ComputeRouteMatrixExtraComputation constants
google.maps.routes.ComputeRouteMatrixExtraComputation
constants
Extra computations to perform for a RouteMatrix.computeRouteMatrix
request.
Access by calling const {ComputeRouteMatrixExtraComputation} = await google.maps.importLibrary("routes")
.
See Libraries in the Maps JavaScript API.
Constants | |
---|---|
TOLLS |
Toll information for the matrix item(s). |
RouteMatrixItemCondition constants
google.maps.routes.RouteMatrixItemCondition
constants
The condition of a route for a given origin/destination pair.
Access by calling const {RouteMatrixItemCondition} = await google.maps.importLibrary("routes")
.
See Libraries in the Maps JavaScript API.
Constants | |
---|---|
ROUTE_EXISTS |
A route was found. |
ROUTE_NOT_FOUND |
No route could be found. |
RouteMatrixItemError class
google.maps.routes.RouteMatrixItemError
class
An error that occurred during RouteMatrix.computeRouteMatrix
for a specific origin/destination pair.
This class extends
Error
.
Access by calling const {RouteMatrixItemError} = await google.maps.importLibrary("routes")
.
See Libraries in the Maps JavaScript API.
Methods | |
---|---|
toJSON |
toJSON() Parameters: None
Return Value:
Object Converts to an object. |
RouteMatrixItemLocalizedValues class
google.maps.routes.RouteMatrixItemLocalizedValues
class
Text representations of the RouteMatrixItem
.
Access by calling const {RouteMatrixItemLocalizedValues} = await google.maps.importLibrary("routes")
.
See Libraries in the Maps JavaScript API.
Properties | |
---|---|
distance |
Type:
string optional Travel distance of the route matrix item in text form. |
distanceLanguage |
Type:
string optional The distance text's BCP-47 language code, such as "en-US" or "sr-Latn". For more information, see http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. |
duration |
Type:
string optional 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 RouteMatrixItemLocalizedValues.staticDuration . |
durationLanguage |
Type:
string optional The duration text's BCP-47 language code, such as "en-US" or "sr-Latn". For more information, see http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. |
staticDuration |
Type:
string optional Duration without taking traffic conditions into consideration, represented in text form. |
staticDurationLanguage |
Type:
string optional The static duration text's BCP-47 language code, such as "en-US" or "sr-Latn". |
transitFare |
Type:
string optional Transit fare, represented in text form. |
transitFareLanguage |
Type:
string optional The transit fare text's BCP-47 language code, such as "en-US" or "sr-Latn". For more information, see http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. |
Methods | |
---|---|
toJSON |
toJSON() Parameters: None
Return Value:
Object Converts to an object. |
RouteMatrixOrigin interface
google.maps.routes.RouteMatrixOrigin
interface
A single origin for a ComputeRouteMatrixRequest
.
Properties | |
---|---|
waypoint |
The location of the origin. A value passed as a string may be an address or plus code. Altitude values for are not taken into consideration. |
routeModifiers optional |
Type:
RouteModifiers optional Modifiers for every route that takes this as the origin. |
RouteModifiers interface
google.maps.routes.RouteModifiers
interface
Encapsulates a set of optional conditions to satisfy when calculating routes.
Properties | |
---|---|
avoidFerries optional |
Type:
boolean optional When set to true , avoids ferries where reasonable, giving preference to routes not containing ferries. Applies only when ComputeRoutesRequest.travelMode is set to DRIVING or TWO_WHEELER . |
avoidHighways optional |
Type:
boolean optional When set to true , avoids highways where reasonable, giving preference to routes not containing highways. Applies only when ComputeRoutesRequest.travelMode is set to DRIVING or TWO_WHEELER . |
avoidIndoor optional |
Type:
boolean optional When set to true , avoids navigating indoors where reasonable, giving preference to routes not containing indoor navigation. Applies only when ComputeRoutesRequest.travelMode is set to WALKING . |
avoidTolls optional |
Type:
boolean optional When set to true , avoids toll roads where reasonable, giving preference to routes not containing toll roads. Applies only when ComputeRoutesRequest.travelMode is set to DRIVING or TWO_WHEELER . |
tollPasses optional |
Type:
Iterable<string> optional Encapsulates information about toll passes. If toll passes are provided, RouteMatrix.computeRouteMatrix tries to return the pass price. If toll passes are not provided, RouteMatrix.computeRouteMatrix treats the toll pass as unknown and tries to return the cash price. Applies only when ComputeRoutesRequest.travelMode is set to DRIVING or TWO_WHEELER . See TollPass for a list of valid values. |
vehicleInfo optional |
Type:
VehicleInfo optional Specifies the vehicle information. |
TransitPreference interface
google.maps.routes.TransitPreference
interface
Preferences for TRANSIT
based routes that influence the route that is returned.
Properties | |
---|---|
allowedTransitModes optional |
Type:
Iterable<TransitMode> optional A set of travel modes to use when getting a TRANSIT route. Defaults to all supported modes of travel. |
routingPreference optional |
Type:
TransitRoutePreference optional A routing preference that, when specified, influences the TRANSIT route returned. |
VehicleEmissionType constants
google.maps.routes.VehicleEmissionType
constants
A set of values describing the vehicle's emission type. Applies only to the DRIVING
travel mode.
Access by calling const {VehicleEmissionType} = await google.maps.importLibrary("routes")
.
See Libraries 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. |
VehicleInfo interface
google.maps.routes.VehicleInfo
interface
Contains the vehicle information, such as the vehicle emission type.
Properties | |
---|---|
emissionType optional |
Type:
VehicleEmissionType optional Describes the vehicle's emission type. Applies only to the DRIVING travel mode. |