GuidesAPI Reference
Guides

Avoidance

Routes can be calculated to avoid specific map features and/or areas.

Avoid areas

Entire geographic areas can be avoided by specifying the areas as a bounding box, a polygon, or a corridor. For example, a route that avoids the Berlin area can be calculated by providing avoid[areas]=bbox:13.082,52.416,13.628,52.626.

For information on how to avoid areas, see How to avoid areas in routes.

Avoid routing zones

For information on routing zones and how to avoid them see How to use routing zones.

Avoid segments

Specific locations of the map can be avoided by providing an identifier of the segments to be avoided. For example, a route that avoids a specific segment, a part of Invalidenstrasse in Berlin, can be calculated by specifying avoid[segments]=here:cm:segment:207551710.

Avoid features

Map features can be avoided by specifying a list of feature categories to be avoided. For example, a route that avoids toll roads can be calculated by specifying avoid[features]=tollRoad when requesting a route.

Avoid highways and toll roads in truck routing

Avoiding highways and/or toll roads for very long truck routes can result in very long response times, or a route not being returned at all. Routing algorithms usually assume that most of the route will take place on a highway, especially for long-distance driving. Breaking this assumption leads to the described behavior. This is a particular problem for truck routes, as the alternative non-highway routes often have more truck restrictions, which can result in a route not being found, or requiring a very long calculation time to find them.

Furthermore, in many countries, most or all main roads are toll-roads (especially for trucks), so the "avoid toll-roads" option faces similar limitations. As an example, routing across Europe with transportMode=truck and avoid[features]=tollRoads would often need to avoid all main roads, and thus result in a very long and inconvenient route for trucks, if it can even be calculated at all.

Avoid seasonal closures

For information on seasonal closures and how to avoid them, see Seasonal closures.

Violations of avoid requests

Sometimes no route is possible without violating the requested avoid. For example, specifying avoid[features]=ferry when routing to an otherwise inaccessible island. In this case, a route can be returned that makes minimal use of the feature. Note that it is also possible that no route is returned when the only route possible would violate the requested avoid.

Or it could be that a route avoiding the feature is too hard to find, because the feature is present on many fast/short routes. An example of this is trying to calculate a route crossing a mountainous region with many tunnels with avoid[feature]=tunnels.

If a route is returned that violates the avoid request a notice is included to indicate that the route doesn't avoid the feature.

Example that avoids the specified avoid option

This request successfully avoids the tollRoad feature using the avoid option:

curl -gX GET 'https://router.hereapi.com/v8/routes?'\
'destination=47.168076,11.861380&'\
'origin=47.257410,11.351458&'\
'transportMode=car&'\
'avoid[features]=tollRoad&'\
'apiKey=YOUR_API_KEY'

Example that violates the specified avoid option

This request violates the avoid option:

curl -gX GET 'https://router.hereapi.com/v8/routes?'\
'destination=53.863531,14.284817&'\
'origin=53.859552,14.271760&'\
'transportMode=car&'\
'avoid[features]=ferry&'\
'apiKey=YOUR_API_KEY'

The response specifies a notice with the code violatedAvoidFerry:

{
  "routes": [
    {
      "id": "7616d85b-da9a-46bd-9b9f-e8dafe34213a",
      "sections": [
        {
          ...,
          "transport": {
            "mode": "car"
          },
          "type": "vehicle"
        },
        {
          ...,
          "notices": [
            {
              "code": "violatedAvoidFerry",
              "title": "Violated avoid ferry"
            }
          ],
          "transport": {
            "mode": "ferry"
          },
          "type": "vehicle"
        },
        {
          ...,
          "transport": {
            "mode": "car"
          },
          "type": "vehicle"
        }
      ]
    }
  ]
}

Example that fails with avoid options

This request fails with the avoid option:

curl -gX GET 'https://router.hereapi.com/v8/routes?'\
'origin=52.531106,13.384915&'\
'transportMode=car&'\
'destination=55.954408,-3.194735&'\
'avoid[features]=ferry,carShuttleTrain&'\
'return=summary&'\
'apiKey=YOUR_API_KEY'
{
  "notices": [
    {
      "title": "Route calculation failed: Couldn't find a route.",
      "code": "noRouteFound"
    }
  ],
  "routes": []
}