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

The new Routes Library, Maps JavaScript API includes theRoute class, which replaces thelegacy Directions Service. This page explains the differences between the legacy directions service and the newRoute class, and provides some code for comparison.

Directions service (Legacy) versus Route class (Beta)

Request parameters

The following table compares the request parameters for the legacy Directions service and theRoute class.

Directions Service (Legacy)Route (Beta)
DirectionsService.route() methodRoute.computeRoutes() method

Required Parameters

originorigin
destinationdestination
travelModetravelMode (optional)

Optional Parameters

optimizeWaypointsoptimizeWaypointOrder
provideRouteAlternativescomputeAlternativeRoutes
avoidFerries,avoidHighways,avoidTollsrouteModifiers
drivingOptionsdepartureTime,trafficModel
regionregion
transitOptionstransitPreference
arrivalTimearrivalTime
unitSystemunits
waypointsintermediates

Methods comparison

The following table compares key methods for the legacy Directions service and theRoute class.

Directions Service (Legacy)Route (Beta)
route() methodcomputeRoutes() method
DirectionsRenderer.setDirections() methodcreatePolylines() method,createWaypointAdvancedMarkers() method

Code comparison

This section compares two similar pieces of code to illustrate the differences between the legacy Directions service and the newRoute class. The code snippets show the code required on each respective API to make a directions request, and then use the result to draw a polyline and markers on the map.

In the legacy Directions service, theDirectionsRenderer object is used to display polylines and markers to represent directions results on a map. In the Routes library, theDirectionsRenderer object has been replaced by thecreatePolylines() andcreateWaypointAdvancedMarkers() methods. This page explains the differences between the legacy Directions Service and the newRoute class, and provides some code for comparison.

Get driving directions

Directions service (Legacy)

The following code gets driving directions using the legacy Directions service, and then uses theDirectionsRenderer to draw a polyline and markers on the map:

// Define a simple request.varrequest={origin:'Mountain View, CA',destination:'San Francisco, CA',travelMode:'DRIVING'};// Call the Directions Service to get the directions.directionsService.route(request,function(result,status){if(status=='OK'){directionsRenderer.setDirections(result);// Add polyline and markers to the map.}});
Important: The legacyDirectionsRenderer object uses the legacyMarker class, which is deprecated.

Route class (Beta)

The following code gets driving directions using the new Route class, then uses thecreatePolylines method to draw a polyline on the map, and thecreateWaypointAdvancedMarkers method to draw markers on the map.

The newRoute class does not automatically render markers. You must callcreateWaypointAdvancedMarkers to render markers.

TypeScript

// Define a routes request.constrequest={origin:'Mountain View, CA',destination:'San Francisco, CA',travelMode:'DRIVING',fields:['path'],// Request fields needed to draw polylines.};// Call computeRoutes to get the directions.const{routes,fallbackInfo,geocodingResults}=awaitRoute.computeRoutes(request);// Use createPolylines to create polylines for the route.mapPolylines=routes[0].createPolylines();// Add polylines to the map.mapPolylines.forEach((polyline)=>polyline.setMap(map));// Create markers to start and end points.constmarkers=awaitroutes[0].createWaypointAdvancedMarkers();// Add markers to the mapmarkers.forEach((marker)=>marker.setMap(map));
Note: Read theguide on using TypeScript and Google Maps.

JavaScript

// Define a routes request.constrequest={origin:'Mountain View, CA',destination:'San Francisco, CA',travelMode:'DRIVING',fields:['path'],// Request fields needed to draw polylines.};// Call computeRoutes to get the directions.const{routes,fallbackInfo,geocodingResults}=awaitRoute.computeRoutes(request);// Use createPolylines to create polylines for the route.mapPolylines=routes[0].createPolylines();// Add polylines to the map.mapPolylines.forEach((polyline)=>polyline.setMap(map));// Create markers to start and end points.constmarkers=awaitroutes[0].createWaypointAdvancedMarkers();// Add markers to the mapmarkers.forEach((marker)=>marker.setMap(map));
Important: TheAdvanced Marker class Requires a map ID to be set in map options. If you don't have a custom map ID, you can useDEMO_MAP_ID.Learn more.

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.