Places UI Kit: A ready-to-use library that provides room for customization and low-code development. Try it out, and share yourinput on your UI Kit experience.

Route Matrix (beta)

RouteMatrixclass

google.maps.routes.RouteMatrixclass

Notice: Available only in thev=beta channel.

A matrix of routes computed for a set of origin/destination pairs byRouteMatrix.computeRouteMatrix

Access by callingconst {RouteMatrix} = await google.maps.importLibrary("routes").
SeeLibraries 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 theComputeRouteMatrixRequest.fields property. The value is a list of field paths.

For example:
  • Field mask of all available fields:fields: ['*']
  • Field mask of Route-level duration and distance:fields: ['durationMillis', 'distanceMeters']

Use of the wildcard response field maskfields: ['*'] is discouraged because:
  • Selecting only the fields that you need helps our server save computation cycles, allowing us to return the result to you with a lower latency.
  • Selecting only the fields that you need in your production job ensures stable latency performance. We might add more response fields in the future, and those new fields might require extra computation time. If you select all fields, or if you select all fields at the top level, then you might experience performance degradation because any new field we add will be automatically included in the response.
  • Selecting only the fields that you need results in a smaller response size, and thus a faster load over the network.

Properties

rows
The rows of the matrix. Each row corresponds to an origin and contains an array ofRouteMatrixItems, each representing a route to a destination.

Methods

toJSON
toJSON()
Parameters:  None
Return Value: Object
Converts to an object.

RouteMatrixRowclass

google.maps.routes.RouteMatrixRowclass

Notice: Available only in thev=beta channel.

Corresponds to an origin passed toRouteMatrix.computeRouteMatrix. Contains a list ofRouteMatrixItems, each item representing a route to a destination.

Access by callingconst {RouteMatrixRow} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.

Properties

items
The route information for each destination.

Methods

toJSON
toJSON()
Parameters:  None
Return Value: Object
Converts to an object.

RouteMatrixItemclass

google.maps.routes.RouteMatrixItemclass

Notice: Available only in thev=beta channel.

Contains route information computed for an origin/destination pair passed toRouteMatrix.computeRouteMatrix.

Access by callingconst {RouteMatrixItem} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.

Properties

condition
Indicates whether the route was found or not.
distanceMeters
Type: numberoptional
The travel distance of the route in meters.
durationMillis
Type: numberoptional
The length of time needed to navigate the route in milliseconds. If you setComputeRouteMatrixRequest.routingPreference toTRAFFIC_UNAWARE, then this value is the same asRouteMatrixItem.staticDurationMillis. If you setComputeRouteMatrixRequest.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 isNumber.POSITIVE_INFINITY.
error
Type: RouteMatrixItemErroroptional
Error that occurred during the computation of the route.
fallbackInfo
Type: FallbackInfooptional
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
Text representations of properties of theRouteMatrixItem.
staticDurationMillis
Type: numberoptional
The duration of traveling through the route without taking traffic conditions into consideration.

Note: If the duration exceeds 2^53 milliseconds, then this value isNumber.POSITIVE_INFINITY.
travelAdvisory
Type: RouteTravelAdvisoryoptional
Additional information about the route.

ComputeRouteMatrixRequestinterface

google.maps.routes.ComputeRouteMatrixRequestinterface

Notice: Available only in thev=beta channel.

Request for a route matrix.

Properties

destinations
Array of destinations, which determines the columns of the response matrix. A value passed as a string may be an address, aplus code, or a Place resource name. Altitude values are not taken into consideration.
fields
Type: Iterable<string>
Collection of fields to be fetched. Specify["*"] for all fields.
origins
Array of origins, which determines the rows of the response matrix. A value passed as a string may be an address, aplus code, or a Place resource name. Altitude values are not taken into consideration.

Several size restrictions apply to the cardinality of origins and destinations:
  • The total number of origins and destinations specified asstrings orPlaces must be no greater than 50.
  • The product of the number of origins and the number of destinations must be no greater than 625.
  • The product of the number of origins and destinations must be no greater than 100 ifComputeRouteMatrixRequest.routingPreference is set toTRAFFIC_AWARE_OPTIMAL.
  • The product of the number of origins and destinations must be no greater than 100 ifComputeRouteMatrixRequest.travelMode is set toTRANSIT.
arrivalTimeoptional
Type: Dateoptional
The arrival time.

Note: Can only be set whenComputeRouteMatrixRequest.travelMode is set toTRANSIT. You can specify eitherComputeRouteMatrixRequest.departureTime orComputeRouteMatrixRequest.arrivalTime, but not both. Transit trips are available for up to 7 days in the past or 100 days in the future.
departureTimeoptional
Type: Dateoptional
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 whenComputeRouteMatrixRequest.travelMode is set toTRANSIT. Transit trips are available for up to 7 days in the past or 100 days in the future.
extraComputationsoptional
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 inComputeRouteMatrixRequest.fields to be returned in the response.
languageoptional
Type: stringoptional
The 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 first origin.
regionoptional
Type: stringoptional
The 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 first origin.
routingPreferenceoptional
Type: RoutingPreferenceoptional
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 whenComputeRouteMatrixRequest.travelMode isDRIVING orTWO_WHEELER, otherwise the request fails.
trafficModeloptional
Type: TrafficModeloptional
Specifies the assumptions to use when calculating time in traffic. This setting affects the value returned inRouteMatrixItem.durationMillis which contains the predicted time in traffic based on historical averages.ComputeRouteMatrixRequest.trafficModel is only available for requests that have setComputeRouteMatrixRequest.routingPreference toTRAFFIC_AWARE_OPTIMAL andComputeRouteMatrixRequest.travelMode toDRIVING. Defaults toBEST_GUESS.
transitPreferenceoptional
Type: TransitPreferenceoptional
Specifies preferences that influence the route returned forTRANSIT routes.

Note: Can only be specified whenComputeRouteMatrixRequest.travelMode is set toTRANSIT.
travelModeoptional
Type: TravelModeoptional
Specifies the mode of transportation.
unitsoptional
Type: UnitSystemoptional
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.

ComputeRouteMatrixExtraComputationconstants

google.maps.routes.ComputeRouteMatrixExtraComputationconstants

Notice: Available only in thev=beta channel.

Extra computations to perform for aRouteMatrix.computeRouteMatrix request.

Access by callingconst {ComputeRouteMatrixExtraComputation} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.

Constants

TOLLSToll information for the matrix item(s).

RouteMatrixItemConditionconstants

google.maps.routes.RouteMatrixItemConditionconstants

Notice: Available only in thev=beta channel.

The condition of a route for a given origin/destination pair.

Access by callingconst {RouteMatrixItemCondition} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.

Constants

ROUTE_EXISTSA route was found.
ROUTE_NOT_FOUNDNo route could be found.

RouteMatrixItemErrorclass

google.maps.routes.RouteMatrixItemErrorclass

Notice: Available only in thev=beta channel.

An error that occurred duringRouteMatrix.computeRouteMatrix for a specific origin/destination pair.

This class extendsError.

Access by callingconst {RouteMatrixItemError} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.

Methods

toJSON
toJSON()
Parameters:  None
Return Value: Object
Converts to an object.

RouteMatrixItemLocalizedValuesclass

google.maps.routes.RouteMatrixItemLocalizedValuesclass

Notice: Available only in thev=beta channel.

Text representations of theRouteMatrixItem.

Access by callingconst {RouteMatrixItemLocalizedValues} = await google.maps.importLibrary("routes").
SeeLibraries in the Maps JavaScript API.

Properties

distance
Type: stringoptional
Travel distance of the route matrix item in text form.
distanceLanguage
Type: stringoptional
The 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: stringoptional
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 asRouteMatrixItemLocalizedValues.staticDuration.
durationLanguage
Type: stringoptional
The 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: stringoptional
Duration without taking traffic conditions into consideration, represented in text form.
staticDurationLanguage
Type: stringoptional
The static duration text's BCP-47 language code, such as "en-US" or "sr-Latn".
transitFare
Type: stringoptional
Transit fare, represented in text form.
transitFareLanguage
Type: stringoptional
The transit fare 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: Object
Converts to an object.

RouteMatrixOrigininterface

google.maps.routes.RouteMatrixOrigininterface

Notice: Available only in thev=beta channel.

A single origin for aComputeRouteMatrixRequest.

Properties

waypoint
The location of the origin. A value passed as a string may be an address orplus code. Altitude values for are not taken into consideration.
routeModifiersoptional
Type: RouteModifiersoptional
Modifiers for every route that takes this as the origin.

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-10-01 UTC.