javascript – Wrapping latitude and longitude points with a 20m by 20m box (Google Maps API V3)

javascript – Wrapping latitude and longitude points with a 20m by 20m box (Google Maps API V3)

I believe this question includes code that should let you accomplish what youre looking for.

I would use Mike Williams eshapes library which I ported to the Google Maps API v3 to make squares with a radius of 20*sqrt(2)/2 meters.

example using my port of Mike Williams eshapes library

The click listener would be:

google.maps.event.addListener(map, click, function(evt) {
  var marker = new google.maps.Marker({ position: evt.latLng, map: map});
  var square = google.maps.Polyline.RegularPoly(evt.latLng,20*Math.sqrt(2)/2,4,0,#ff0000,1,1);
  square.setMap(map);
});

working example

Simpler working example based off alternate answer in link from Kelvin Mackay

javascript – Wrapping latitude and longitude points with a 20m by 20m box (Google Maps API V3)

Leave a Reply

Your email address will not be published.