3

I want to create map listener being able to draw polygons snapped to roads. These polygons will be some areas limited by streets. I'm trying to achieve that by using Directions API. When user clicks near to the road, it works fine - point is snapped to the closest point on the road. Of course I'm collecting points contained by path, to create polygon later.

There is a problem with streets' directions. Often when I click some point, the path is created in roundabout way. This occurs when I use any type of TravelMode, even google.maps.TravelMode.WALKING. See the image for details.

enter image description here Red lines shows what I want to obtain and black lines is the path generated by Directions API.

Is there any way to ignore streets' directions? I mean when I click some point near to road, the point is snapped to center of the road, regardless if it is possible to get there from previously clicked point. Maybe there are some other approaches to select areas by streets?

  • Do you have the clicked points that generated that line or a live example? I would be surprised if walking directions generated lots of those "detours". – geocodezip Nov 07 '12 at 05:02
  • I stand corrected [example driving](http://www.geocodezip.com/v3_example_geo2.asp?waypts=yes&addr1=(52.19605,20.92927)&geocode=1&addr2=(52.19605,20.92927)&geocode=2&waypt=(52.219572,20.97109)&waypt=(52.2169,21.005057)&waypt=(52.180012,21.021107)&waypt=(52.178341,21.001302)&waypt=(52.190379,20.958021)), [example walking](http://www.geocodezip.com/v3_example_geo2.asp?walking=yes&waypts=yes&addr1=(52.19605,20.92927)&geocode=1&addr2=(52.19605,20.92927)&geocode=2&waypt=(52.219572,20.97109)&waypt=(52.2169,21.005057)&waypt=(52.180012,21.021107)&waypt=(52.178341,21.001302)&waypt=(52.190379,20.958021)) – geocodezip Nov 07 '12 at 06:00

1 Answers1

1

Use a modifier key (like "shift") to turn off the DirectionsService results and draw the line straight to the mouse.

See my example: http://people.missouristate.edu/chadkillingsworth/mapsexamples/snaptoroad.htm

Chad Killingsworth
  • 14,360
  • 2
  • 34
  • 57
  • Thanks for answer, but it is not a solution for this problem. When I turn off DirectionsService, paths will be not snapped to roads. I need all paths to be snapped to roads but without roundabout ways. – Karol Lewandowski Nov 07 '12 at 21:32
  • I figured that, but I'm not sure you are going to get the answer you want. – Chad Killingsworth Nov 07 '12 at 23:05
  • 1
    I got the new idea, but I'm not sure if it is good. I could find two paths between two last selected points: from A to B and from B to A. Then I select the shorter one - it should be generated without (or at least with less amount) of roundabout ways. I will try this approach in a few days and let you know if it works. The only drawback I see is excessive usage of API. – Karol Lewandowski Nov 08 '12 at 00:24