<iframe src="https://developers.devsite.google/frame/maps/documentation/javascript/reference/route-matrix_1dc2c85f7da2dcdc7e82bc99a378139fe8ab4746c6891fddd9af68ed2c1f9cb1.frame" class="framebox inherit-locale redirect-iframe" allow="clipboard-write https://developers.devsite.google" allowfullscreen is-upgraded></iframe>

## [RouteMatrix](https://developers.google.com/maps/documentation/javascript/reference/route-matrix.md.txt#RouteMatrix)
class


class
`google.maps.routes.RouteMatrix`

library `"routes"`

A matrix of routes computed for a set of origin/destination pairs by `RouteMatrix.computeRouteMatrix`

```javascript
const {RouteMatrix} = await google.maps.importLibrary("routes");
```

| ### Static Methods ||
|---|---|
| `computeRouteMatrix` | `computeRouteMatrix(request)` **Parameters:** - `request: ComputeRouteMatrixRequest` **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: - Field mask of all available fields: `fields: ['*']` - Field mask of Route-level duration and distance: `fields: ['durationMillis', 'distanceMeters']` <br /> Use of the wildcard response field mask `fields: ['*']` 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` readonly | **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 ||
|---|---|

## [RouteMatrixRow](https://developers.google.com/maps/documentation/javascript/reference/route-matrix.md.txt#RouteMatrixRow)
class


class
`google.maps.routes.RouteMatrixRow`

library `"routes"`

Corresponds to an origin passed to `RouteMatrix.computeRouteMatrix`. Contains a list of `RouteMatrixItem`s, each item representing a route to a destination.

```javascript
const {RouteMatrixRow} = await google.maps.importLibrary("routes");
```

| ### Properties ||
|---|---|
| `items` readonly | **Type:** `Array<RouteMatrixItem>` The route information for each destination. |

| ### Methods ||
|---|---|

## [RouteMatrixItem](https://developers.google.com/maps/documentation/javascript/reference/route-matrix.md.txt#RouteMatrixItem)
class


class
`google.maps.routes.RouteMatrixItem`

library `"routes"`

Contains route information computed for an origin/destination pair passed to `RouteMatrix.computeRouteMatrix`.

```javascript
const {RouteMatrixItem} = await google.maps.importLibrary("routes");
```

| ### Properties ||
|---|---|
| `condition` readonly | **Type:** `RouteMatrixItemCondition optional` Indicates whether the route was found or not. |
| `distanceMeters` readonly | **Type:** `number optional` The travel distance of the route in meters. |
| `durationMillis` readonly | **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` readonly | **Type:** `RouteMatrixItemError optional` Error that occurred during the computation of the route. |
| `fallbackInfo` readonly | **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` readonly | **Type:** `RouteMatrixItemLocalizedValues optional` Text representations of properties of the `RouteMatrixItem`. |
| `staticDurationMillis` readonly | **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` readonly | **Type:** `RouteTravelAdvisory optional` Additional information about the route. |

## [ComputeRouteMatrixRequest](https://developers.google.com/maps/documentation/javascript/reference/route-matrix.md.txt#ComputeRouteMatrixRequest)
interface


interface
`google.maps.routes.ComputeRouteMatrixRequest`

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, a [plus code](https://plus.codes), 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` | **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, a [plus code](https://plus.codes), 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 as `string`s or `Place`s 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 if `ComputeRouteMatrixRequest.routingPreference` is set to `TRAFFIC_AWARE_OPTIMAL`. - The product of the number of origins and destinations must be no greater than 100 if `ComputeRouteMatrixRequest.travelMode` is set to `TRANSIT`. |
| `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. |
| `internalUsageAttributionIds` optional | **Type:** `Iterable<string> optional` Identifiers used to attribute calls to specific packages or OSS libraries. |
| `language` optional | **Type:** `string optional` The BCP-47 language code, such as "en-US" or "sr-Latn". For more information, see [Unicode Locale Identifier](http://www.unicode.org/reports/tr35/#Unicode_locale_identifier). See [Language Support](https://developers.google.com/maps/faq.md.txt#languagesupport) 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](https://developers.google.com/maps/documentation/javascript/localization.md.txt#Language). 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](https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains#Country_code_top-level_domains). When you don't provide this value, the region is inferred from your Google Maps JavaScript API [localization settings](https://developers.google.com/maps/documentation/javascript/localization.md.txt#Region). 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](https://developers.google.com/maps/documentation/javascript/reference/route-matrix.md.txt#ComputeRouteMatrixExtraComputation)
constants


constants
`google.maps.routes.ComputeRouteMatrixExtraComputation`

library `"routes"`

Extra computations to perform while completing the request. See the [web service documentation](https://developers.google.com/maps/documentation/routes/reference/rpc/google.maps.routing.v2.md.txt#extracomputation) for more information.

These constants are also usable as strings. In TypeScript, the string literals are defined by the `ComputeRouteMatrixExtraComputationString` type.

```javascript
const {ComputeRouteMatrixExtraComputation} = await google.maps.importLibrary("routes");
```

| ### Constants ||
|---|---|
| `TOLLS` | Toll information for the matrix element(s). See the [web service documentation](https://developers.google.com/maps/documentation/routes/reference/rpc/google.maps.routing.v2.md.txt#extracomputation) for more information. |

## [RouteMatrixItemCondition](https://developers.google.com/maps/documentation/javascript/reference/route-matrix.md.txt#RouteMatrixItemCondition)
constants


constants
`google.maps.routes.RouteMatrixItemCondition`

library `"routes"`

The condition of the route being returned. See the [web service documentation](https://developers.google.com/maps/documentation/routes/reference/rpc/google.maps.routing.v2.md.txt#routematrixelementcondition) for more information.

These constants are also usable as strings. In TypeScript, the string literals are defined by the `RouteMatrixItemConditionString` type.

```javascript
const {RouteMatrixItemCondition} = await google.maps.importLibrary("routes");
```

| ### Constants ||
|---|---|
| `ROUTE_EXISTS` | A route was found, and the corresponding information was filled out for the element. See the [web service documentation](https://developers.google.com/maps/documentation/routes/reference/rpc/google.maps.routing.v2.md.txt#routematrixelementcondition) for more information. |
| `ROUTE_NOT_FOUND` | No route could be found. See the [web service documentation](https://developers.google.com/maps/documentation/routes/reference/rpc/google.maps.routing.v2.md.txt#routematrixelementcondition) for more information. |

## [RouteMatrixItemError](https://developers.google.com/maps/documentation/javascript/reference/route-matrix.md.txt#RouteMatrixItemError)
class


class
`google.maps.routes.RouteMatrixItemError`
extends `Error`

library `"routes"`

An error that occurred during `RouteMatrix.computeRouteMatrix` for a specific origin/destination pair.

```javascript
const {RouteMatrixItemError} = await google.maps.importLibrary("routes");
```

| ### Methods ||
|---|---|

## [RouteMatrixItemLocalizedValues](https://developers.google.com/maps/documentation/javascript/reference/route-matrix.md.txt#RouteMatrixItemLocalizedValues)
class


class
`google.maps.routes.RouteMatrixItemLocalizedValues`

library `"routes"`

Text representations of the `RouteMatrixItem`.

```javascript
const {RouteMatrixItemLocalizedValues} = await google.maps.importLibrary("routes");
```

| ### Properties ||
|---|---|
| `distance` readonly | **Type:** `string optional` Travel distance of the route matrix item in text form. |
| `distanceLanguage` readonly | **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` readonly | **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` readonly | **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` readonly | **Type:** `string optional` Duration without taking traffic conditions into consideration, represented in text form. |
| `staticDurationLanguage` readonly | **Type:** `string optional` The static duration text's BCP-47 language code, such as "en-US" or "sr-Latn". |
| `transitFare` readonly | **Type:** `string optional` Transit fare, represented in text form. |
| `transitFareLanguage` readonly | **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 ||
|---|---|

## [RouteMatrixOrigin](https://developers.google.com/maps/documentation/javascript/reference/route-matrix.md.txt#RouteMatrixOrigin)
interface


interface
`google.maps.routes.RouteMatrixOrigin`

A single origin for a `ComputeRouteMatrixRequest`.

| ### Properties ||
|---|---|
| `waypoint` | **Type:** `string|LatLng|LatLngLiteral|LatLngAltitudeLiteral|DirectionalLocationLiteral|Place|Waypoint` The location of the origin. A value passed as a string may be an address or [plus code](https://plus.codes). Altitude values for are not taken into consideration. |
| `routeModifiers` optional | **Type:** `RouteModifiers optional` Modifiers for every route that takes this as the origin. |