**European Economic Area (EEA) developers**

> [!NOTE]
> If your billing address is in the European Economic Area, effective on 8 July 2025, the [Google Maps Platform EEA Terms of Service](https://cloud.google.com/terms/maps-platform/eea) will apply to your use of the Services. Functionality varies by region. [Learn more](https://developers.google.com/maps/comms/eea/faq.md.txt).

The `RouteMatrix` class replaces the
[Distance Matrix Service, Maps JavaScript API (Legacy)](https://developers.google.com/maps/documentation/javascript/legacy/distancematrix.md.txt).
This page explains the differences between the legacy Distance Matrix service and the new
JavaScript library, and provides some code for comparison.

## Distance Matrix API (Legacy) versus Route Matrix class

The following table compares the request parameters for the legacy
[Distance Matrix API (Legacy)](https://developers.google.com/maps/documentation/javascript/reference/next/distance-matrix) and
the [`RouteMatrix`](https://developers.google.com/maps/documentation/javascript/reference/route-matrix.md.txt) class.

| [Distance Matrix Service, Maps JavaScript API (Legacy)](https://developers.google.com/maps/documentation/javascript/legacy/distancematrix.md.txt) | [`RouteMatrix`](https://developers.google.com/maps/documentation/javascript/reference/route-matrix.md.txt) | Required or optional |
|---|---|---|
| [`origins`](https://developers.google.com/maps/documentation/javascript/legacy/distancematrix.md.txt) | [`origins`](https://developers.google.com/maps/documentation/javascript/reference/route-matrix.md.txt#ComputeRouteMatrixRequest.origins) | Required |
| [`destinations`](https://developers.google.com/maps/documentation/javascript/legacy/distancematrix.md.txt) | [`destinations`](https://developers.google.com/maps/documentation/javascript/reference/route-matrix.md.txt#ComputeRouteMatrixRequest.destinations) | Required |
| [`travelMode`](https://developers.google.com/maps/documentation/javascript/legacy/distancematrix.md.txt) | [`travelMode`](https://developers.google.com/maps/documentation/javascript/reference/route-matrix.md.txt#ComputeRouteMatrixRequest.travelMode) | Optional |
| [`transitOptions`](https://developers.google.com/maps/documentation/javascript/legacy/distancematrix.md.txt) | [`transitPreference`](https://developers.google.com/maps/documentation/javascript/reference/route-matrix.md.txt#ComputeRouteMatrixRequest.transitPreference) | Optional |
| [`arrivalTime`](https://developers.google.com/maps/documentation/javascript/legacy/distancematrix.md.txt) | [`arrivalTime`](https://developers.google.com/maps/documentation/javascript/reference/route-matrix.md.txt#ComputeRouteMatrixRequest.arrivalTime) | Optional |
| [`drivingOptions`](https://developers.google.com/maps/documentation/javascript/legacy/distancematrix.md.txt#driving_options) | [`departureTime`](https://developers.google.com/maps/documentation/javascript/reference/route-matrix.md.txt#ComputeRouteMatrixRequest.departureTime), [`trafficModel`](https://developers.google.com/maps/documentation/javascript/reference/route-matrix.md.txt#ComputeRouteMatrixRequest.traffic_model) | Optional |
| [`unitSystem`](https://developers.google.com/maps/documentation/javascript/legacy/distancematrix.md.txt#distance_matrix_requests) | [`units`](https://developers.google.com/maps/documentation/javascript/reference/route-matrix.md.txt#ComputeRouteMatrixRequest.units) | Optional |
| [`avoidHighways`](https://developers.google.com/maps/documentation/javascript/legacy/distancematrix.md.txt#driving_options), [`avoidTolls`](https://developers.google.com/maps/documentation/javascript/legacy/distancematrix.md.txt#driving_options) | [`RouteModifiers`](https://developers.google.com/maps/documentation/javascript/reference/route-matrix.md.txt#RouteModifiers) | Optional |

## Code comparison

This section compares two similar pieces of code to illustrate the differences between the
Distance Matrix API (Legacy) and the new `RouteMatrix` class. The code snippets show
the code required on each respective API to make a directions request, and view the results.

### Distance Matrix API (Legacy)

The following code makes a distance matrix request using the Distance Matrix API (Legacy).

```javascript
// Define the request.
const request = {
  origins: [{lat: 55.93, lng: -3.118}, 'Greenwich, England'],
  destinations: ['Stockholm, Sweden', {lat: 50.087, lng: 14.421}],
  travelMode: 'DRIVING',
  drivingOptions: {
    departureTime: new Date(Date.now()),
    trafficModel: 'optimistic'
  }
};

// Make the request.
service.getDistanceMatrix(request).then((response) => {
  // Display the response.
  document.getElementById("response").textContent = JSON.stringify(
    response,
    null,
    2,
  );
});
    
```

### Route Matrix class


The following code makes a distance matrix request using the new Route Matrix class:

```javascript
// Define the request.
const request = {
  origins: [{lat: 55.93, lng: -3.118}, 'Greenwich, England'],
  destinations: ['Stockholm, Sweden', {lat: 50.087, lng: 14.421}],
  travelMode: 'DRIVING',
  departureTime: new Date(),
  trafficModel: 'optimistic'
};

// Make the request.
const response = await RouteMatrix.computeRouteMatrix(request);

// Display the response.
document.getElementById("response").setValue(JSON.stringify(response, null, 2,));
    
```