httphere-api

HERE Routing API - How do I avoid multiple avoidance areas as polygons in a route request?


I have tried following the article which allows for up to 20 polygons to be added as avoidance areas in a route request. https://www.here.com/learn/blog/routing-supports-polygons-for-avoid-areas

I am able to get a desired response using the http request: GET https://router.hereapi.com/v8/routes?origin=33.751305,-118.188812&destination=34.092232,-117.435051&transportMode=car&avoid[areas]=polygon:34.073334,-118.027496;33.888504,-117.813255;33.895847,-118.220070&apiKey={YOUR API KEY}

However I am clueless as to how I can make a request with multiple polygons.

I have tried various methods to add a 2nd polygon to the request, of which none have worked.

Using an semicolon to seperate the polygons which results in a malformed request error: GET https://router.hereapi.com/v8/routes?origin=33.751305,-118.188812&destination=34.092232,-117.435051&transportMode=car&avoid[areas]=polygon:34.073334,-118.027496;33.888504,-117.813255;33.895847,-118.220070;polygon:54.073334,-118.027496;53.888504,-117.813255;53.895847,-118.220070&apiKey={YOUR API KEY}

Using an exclaimation mark to seperate the polygons which results in a malformed request error: GET https://router.hereapi.com/v8/routes?origin=33.751305,-118.188812&destination=34.092232,-117.435051&transportMode=car&avoid[areas]=polygon:34.073334,-118.027496;33.888504,-117.813255;33.895847,-118.220070!polygon:54.073334,-118.027496;53.888504,-117.813255;53.895847,-118.220070&apiKey={YOUR API KEY}

Adding another avoid[areas] where the response complains that multiple avoid[areas] cannot be used. GET https://router.hereapi.com/v8/routes?origin=33.751305,-118.188812&destination=34.092232,-117.435051&transportMode=car&avoid[areas]=polygon:34.073334,-118.027496;33.888504,-117.813255;33.895847,-118.220070&avoid[areas]=polygon:54.073334,-118.027496;53.888504,-117.813255;53.895847,-118.220070&apiKey={YOUR API KEY}


Solution

  • To add multiple polygon, you need to use "|" as a separator like the example below. https://router.hereapi.com/v8/routes?apikey=Your_API_Key&origin=33.751305,-118.188812&destination=34.092232,-117.435051&transportMode=car&avoid[areas]=polygon:34.07508,-117.94758;33.89025,-117.73334;33.89759,-118.14015|polygon:54.073334,-118.027496;53.888504,-117.813255;53.895847,-118.22007