Routing API v7 Developer's Guide

Requesting a Route Avoiding an Area

To calculate directions between two coordinates without traveling through a specified area, use the CalculateRouteRequest service specifying the start (waypoint0), endpoint (waypoint1) and area to avoid (avoidareas as a rectangular area, defining the top left and bottom right corners). The string geo! indicates that you are specifying each point using latitude and longitude.

Note that you also have to specify an apiKey or app_id and app_code if you are using the app_id/app_code authentication (see Acquiring Credentials), type of route calculation and whether to take traffic into account.

Note: These examples use a HERE API Key to authenticate your request. For information on other possible options, see Authentication Guide. For examples of how to use the other authentication options with the Routing API v7, see Authentication Examples.

The following example calculates a route from the Westin Grand hotel (52.516858379, 13.3884717) at Unter den Linden in Berlin to the Staatsoper in Berlin (52.51733824, 13.394678415) avoiding passing the Deutsche Guggenheim (52.51704771, 13.39131492) by specifying a rectangle that contains it (top left 52.517100760,13.3905424488 and bottom right 52.5169701849,13.391808451), and also the fastest route for a car without taking traffic conditions into account.

https://route.ls.hereapi.com/routing/7.2/calculateroute.json
?apiKey={YOUR_API_KEY}
&waypoint0=geo!52.516858379,13.3884717
&waypoint1=geo!52.51733824,13.394678415
&mode=fastest;car;traffic:disabled
&avoidareas=52.517100760,13.3905424488;52.5169701849,13.391808451
Figure 1. Example of route avoiding an area
In the following example multiple rectangular areas are specified. The query results in a route avoiding all specified areas.
Note: You need to specify multiple avoid areas and use the "!" character as a separator. You can specify up to 20 areas to avoid.
https://route.ls.hereapi.com/routing/7.2/calculateroute.json
?apiKey={YOUR_API_KEY}
&waypoint0=geo!52.5184443440238,13.383906494396967
&waypoint1=geo!52.51435421904425,13.396947378094524
&mode=fastest;car;traffic:disabled
&avoidareas=52.517100760,13.3905424488;52.5169701849,13.391808451!
52.51623131288022,13.389888672738778;52.51335487996589,13.395274548440511!
52.52006148651319,13.385160024545286;52.517760038213815,13.389707563495335
Figure 2. Example of route avoiding multiple areas

In the following example, an area is specified in a way that it cannot be avoided. Note that the routeattributes request parameter is used to obtain notes.

https://route.ls.hereapi.com/routing/7.2/calculateroute.json
?apiKey={YOUR_API_KEY}
&waypoint0=geo!52.51698477564798,13.390274028311126
&waypoint1=geo!52.51708923597271,13.392055015097014
&mode=fastest;car;traffic:disabled
&routeattributes=sh,no
&avoidareas=52.517100760,13.3905424488;52.5169701849,13.391808451

In this case, the resulting route passes through the specified area and the JSON output contains a "violation" note.

note : [ <1 elem>
  0 : {
    type : "violation"
    code : "routingOptionViolated"
    text : "blockedRoad"
  }
]
Figure 3. Example of route not possible to avoid specified area