Blacklisting specific roads from Google Maps/Mapquest?

前端 未结 4 1046
感情败类
感情败类 2020-12-03 08:28

I\'m looking to build a custom view of a Google Maps type of application for providing directions, but I need to blacklist specific roads or sections of roads. I\'m not tal

相关标签:
4条回答
  • 2020-12-03 08:32

    I think mapquest lets you do this, see http://www.mapquestapi.com/directions/#output and check out the section for mustAvoidLinkId's and tryAvoidLinkId's

    0 讨论(0)
  • 2020-12-03 08:43

    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.

    1. 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.

    2. 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.

    0 讨论(0)
  • 2020-12-03 08:46

    There is an open feature request about this issue on the Google Maps API Issue Tracker:

    • Roadblock definitions into GDirections as coordinate points

    The issue has been acknowledged by Google, but it remains open. You may want to vote up the issue to signal to Google the demand for this feature.

    0 讨论(0)
  • 2020-12-03 08:48

    I tried all google maps alternatives, and none of them allows the possibility to define road that avoids certain road except Here maps. I am delighted with this solution and it solved all my problems https://developer.here.com/documentation/routing/topics/route-avoiding-links-and-areas.html

    You don't need to blacklist the whole road, you can blacklist only some part of that road and the map will try to avoid that if possible.

    0 讨论(0)
提交回复
热议问题