How can the HERE Routing API be used to avoid a specific section of road?

417 Views Asked by At

I'm trying to get a route that avoids a specific section of a road using Here routing API. I tried passing in a rectangle area to avoid the road like avoid[areas]=bbox:13.082,52.416,13.628,52.62. The problem is that the road I'm trying to avoid is diagonal. Using a rectangle to define the coordinates of the beginning and end of the diagonal road ends up causing nearby roads to be avoided. What would help me is if I could avoid an area in the shape of a polygon. Is there a better way to get directions that avoid a road?

1

There are 1 best solutions below

0
On

You can use the avoid[segments] parameter to indicate that you want to avoid a specific section of the road. Here's an example request including this parameter:

https://router.hereapi.com/v8/routes?
apikey=*******&
origin=52.508900,13.388871&
destination=52.512990,13.390536&
return=polyline,summary,actions,instructions&
transportMode=car&
avoid[segments]=here:cm:segment:88390186

The easiest way to find out what's the Segment ID for the section of the road you want to avoid is by calculating a route where both the origin and destination are set to the coordinates of that section, and request the segmentId attribute in the spans parameter:

https://router.hereapi.com/v8/routes?
apikey=*******&
origin=52.51143775483142,13.386767963569321&
destination=52.51143775483142,13.386767963569321&
return=polyline&
spans=segmentId&
transportMode=car