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.

Migrate to the Route Matrix class

European Economic Area (EEA) developers If your billing address is in the European Economic Area, effective on 8 July 2025, the Google Maps Platform EEA Terms of Service will apply to your use of the Services. Functionality varies by region.Learn more.

TheRouteMatrix class replaces theDistance Matrix Service, Maps JavaScript API (Legacy). 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 (Beta)

The following table compares the request parameters for the legacyDistance Matrix API and theRouteMatrix class.

Distance Matrix Service (Legacy)RouteMatrix (Beta)

Required Parameters

originsorigins
destinationsdestinations

Optional Parameters

travelModetravelMode
transitOptionstransitPreference
arrivalTimearrivalTime
drivingOptionsdepartureTime,trafficModel
unitSystemunits
avoidHighways,avoidTollsRouteModifiers

Code comparison

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

Directions API (Legacy)

The following code makes a distance matrix request using the legacy Distance Matrix API.

// Define the request.constrequest={origins:[{lat:55.93,lng:-3.118},'Greenwich, England'],destinations:['Stockholm, Sweden',{lat:50.087,lng:14.421}],travelMode:'DRIVING',drivingOptions:{departureTime:newDate(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 (Beta)

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

// Define the request.constrequest={origins:[{lat:55.93,lng:-3.118},'Greenwich, England'],destinations:['Stockholm, Sweden',{lat:50.087,lng:14.421}],travelMode:'DRIVING',departureTime:newDate(),trafficModel:'optimistic'};// Make the request.constresponse=awaitRouteMatrix.computeRouteMatrix(request);// Display the response.document.getElementById("response").setValue(JSON.stringify(response,null,2,));

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-02 UTC.