Get a Maps Demo Key: Try out select Maps JavaScript API and Places UI Kit features at no cost with a Maps Demo Key—no billing information required.

Specify features to avoid

European Economic Area (EEA) developers

Specify which route features you prefer to avoid, such as avoiding tolls or highways, by adding route modifiers to a request. The API then attempts to provide a route that does not require those features.

You specify which route features you prefer to avoid, such as avoiding tolls or highways, by adding route modifiers to a request. The API then attempts to provide a route that does not require those features.

Use the routeModifiers property in a request, of type RouteModifiers. 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.

Example

The following example demonstrates how to set a route modifier to avoid tolls in a computeRoutes request.

constrequestWithAvoid={
origin:'Kirkland, WA',
destination:'University of Washington',
travelMode:'DRIVING',
routeModifiers:{
avoidTolls:true,
},
fields:['path'],
};

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026年09月01日 UTC.