如何使用HERE路由API来避开特定路段



我正在尝试使用Here routing API获得一条避开特定路段的路线。我试着在一个矩形区域内通过,以避开像avoid[areas]=bbox:13.082,52.416,13.628,52.62那样的道路。问题是我要避开的路是斜的。使用矩形来定义对角线道路起点和终点的坐标,最终会导致避开附近的道路。对我有帮助的是,如果我能避开多边形的区域。有没有更好的方法来获得避开道路的方向?

您可以使用避免[路段]参数来指示您想要避开特定路段。下面是一个包含此参数的示例请求:

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

找出要避开的路段的路段ID的最简单方法是计算一条路线,其中起点和终点都设置为该路段的坐标,并请求跨度参数中的segmentId属性:

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