Google API (directions) - creating routes that avoid certain points [duplicate]

人走茶凉 提交于 2019-12-22 08:54:53

问题


Google Maps API does not seem to provide a means to create routes that avoid or tend to avoid certain points. Has anyone worked on something like this? I want to create exception rules on routes.

For example: show routes that do not have traffic signals.


回答1:


I had the same problem and this is by far the best solution i have found.

"As mentioned in another answer, this functionality is not directly available in the Google Maps API. However, I've been thinking about it, and had a couple of work-around ideas in the "hacking it together" category. Both of these rely on version 3 of the Google Maps API.

When requesting the directions, set provideRouteAlternatives to true. Loop through the alternatives. Check if that route passes through one of your roadblocks. If it does, discard that route and try the next one.

For each roadblock, set up in advance one or more alternate points to route through. For example, if you want to avoid a certain bridge, identify one or more alternate bridges to use. Now, if a route passes through one of your roadblocks, add the alternate point for the for roadblock as a waypoint (with stopover set to false). Now run the directions again and they should avoid the roadblock and use the alternate.

Neither of these methods are optimal, but depending on your situation, they might work for you."

Source Blacklisting specific roads from Google Maps/Mapquest?



来源:https://stackoverflow.com/questions/19144100/google-api-directions-creating-routes-that-avoid-certain-points

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!