Route Matrix

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.

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:
  • Field mask of all available fields: fields: ['*']
  • Field mask of Route-level duration and distance: fields: ['durationMillis', 'distanceMeters']

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.
rows
The rows of the matrix. Each row corresponds to an origin and contains an array of