How to exclude territories from routing
The exclude[countries] and exclude[states] parameters allow you to calculate routes that exclude specific territories from routing.
Use these parameters to ensure that the route never goes through these states or countries.
For example, if the origin or destination of the route is in an excluded territory, the route calculation fails.
Exclude countries
In this example, the route calculation request uses the exclude[countries] parameter to exclude Switzerland from route calculation.
curl -gX GET 'https://router.hereapi.com/v8/routes?'\
'origin=45.474427,9.138537&'\
'destination=50.096988,8.66033&'\
'return=polyline&'\
'transportMode=car&'\
'exclude[countries]=CHE&'\
'apiKey=YOUR_API_KEY'The route marked with blue shows a route that excludes Switzerland, as per the provided sample request.
The route marked with purple shows the route calculated by the API when Switzerland isn't excluded using exclude[countries]=CHE.
Exclude states
You can exclude territories at a more granular level using the exclude[states] parameter.
State exclusion is supported in selected countries.
For a full list, see Countries which support state exclusion.
In this example, the route calculation request from Tucumcari to Oklahoma City excludes the state of Texas.
curl -gX GET 'https://router.hereapi.com/v8/routes?'\
'origin=35.171888,-103.724999&'\
'destination=35.46546193,-97.52597214&'\
'return=polyline&'\
'transportMode=car&'\
'exclude[states]=USA:TX&'\
'apiKey=YOUR_API_KEY'The route marked with purple shows a route that excludes Texas, as per the provided sample request.
The route marked with blue shows the route calculated by the API when Texas isn't excluded using exclude[states]=USA:TX.
No detour available
When excluding territories, HERE Routing API v8 reliably offers detours that honor user's exclusion settings. There are, however, limits to the APIs ability to calculate detours. One such example is calculating a route from Berlin to Vilnius while avoiding Poland.
Run this sample request to see that the calculation fails:
curl -gX GET 'https://router.hereapi.com/v8/routes?'\
'origin=52.494438,13.40415&'\
'destination=54.679577,25.254137&'\
'return=polyline&'\
'transportMode=car&'\
'exclude[countries]=POL&'\
'apiKey=YOUR_API_KEY'Next steps
- See the API Reference to learn more about using the
excludeparameter. - See Avoidance to learn about avoidance in routing, which is less strict than excluding territories.
Updated 9 days ago