The Routes API is currently in Preview (pre-GA). Pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. Pre-GA Offerings are covered by the Google Maps Platform Service Specific Terms. For more information, see the launch stage descriptions.

Configure route modifiers

Stay organized with collections Save and categorize content based on your preferences.

Adding route modifiers to a request lets you specify conditions to apply when the API calculates a route, such as avoiding tools or highways.

Use the routeModifiers property in a request, of type RouteModifiers, to specify conditions when calculating the routes. For example, you can specify avoidTolls, avoidHighways, avoidFerries, and avoidIndoor.

Specifying a route modifier does not necessarily eliminate routes that include the restricted feature. The API uses the modifier to bias the result to more favorable routes. There can be a few reasons why requesting an avoidance option doesn't change your route. For example, the only route from the origin to the destination makes it impossible to avoid a highway or ferry. Or, the alternate route actually lengthens travel time significantly.

The following example demonstrates how to set route modifiers in a computeRoutes method (REST) request body. You can also specify this option to the ComputeRoutes method (gRPC). In this example, you specify to avoid tolls and highways:

{
  "origin":{
    "location":{
      "latLng":{
        "latitude":37.419734,
        "longitude":-122.0827784
      }
    }
  },
  "destination":{
    "location":{
      "latLng":{
        "latitude":37.417670,
        "longitude":-122.079595
      }
    }
  },
  "routeModifiers": {
    "avoidTolls": true,
    "avoidHighways": true,
  }
}