1

Seems like this one maybe too hard even for the gurus so I will try and re-word it to try and get some response: I am trying to add a vertex or vertices to an existing polygon intelligently without crossovers or self-intersection but all I can find is the following complex V2 example: http://www.kashey.ru/pages/maps/basic_poly_editor_test.php# I would like to do the same thing but with Google Maps api V3 instead. Does anybody know of a way of detecting which existing polygon side or polygon edge is the closest or nearest to a point you click near that polygon? I believe this requires some serious maths and trig functions but so far I can't find anyone who has done it with Google Maps api V3. Maybe if somebody could tell me how to convert the V2 code above to V3 then I could run with that. Any help would be really appreciated.

Optorock
  • 19
  • 7

1 Answers1

0

Try this:

 <html>
 <head>
   <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3&sensor=false"></script>
 </head>
 <body>
 <div id="map-canvas" style="width: 100%; height: 100%; margin: 0; padding: 0;">map</div>
 <script type="text/javascript">
   google.maps.event.addDomListenerOnce(window, 'load', function initialize() {
     var container = document.getElementById('map-canvas');
     var map = new google.maps.Map(container, {
      center: new google.maps.LatLng(37.4419, -122.1419),
     zoom: 13
     });


     var vertexes = [
       new google.maps.LatLng(37.4419     , -122.1419),
       new google.maps.LatLng(37.4419+0.03, -122.1419),
       new google.maps.LatLng(37.4419     , -122.1419+0.03)
     ];

     var polygon = new google.maps.Polygon({
         paths: vertexes,
         editable: true,
         map: map
     });
   });
 </script>
 </body>
 </html>
Steve Jansen
  • 9,398
  • 2
  • 29
  • 34
  • A big thank you Steve that is 9 years and 4 months overdue. I'm sorry but I just didn't see your reply, maybe Stackoverflow didn't notify me, I just don't know but I have only now just discovered it. I did get the problem sorted back then and the page has been working with no changes since way back then. If you are interested,the page is at: https://payback.co.nz/Land_Area_&_Distance_Calculator.html Please reply to the email on that home page. Regards Paul (Optorock) – Optorock Apr 19 '23 at 02:56