Gabotronix
1 month ago

Get coordinates of drawn rectangle in google maps

Posted 1 month ago by Gabotronix

Hi everybody, I got the code to draw a draggable rectangle in google maps

https://jsbin.com/harawira/1/edit?html,js,output

I know I can get the coordinates of a rectangle by its bounds like in code bellow but in my drawing code I don't have a reference to the drawn rectangle, how can I get NE and SW of a drawn rectangle?

var bounds = rectangle.getBounds();
var NE = bounds.getNorthEast();
var SW = bounds.getSouthWest();
// North West
var NW = new google.maps.LatLng(NE.lat(),SW.lng());
// South East
var SE = new google.maps.LatLng(SW.lat(),NE.lng());

Please sign in or create an account to participate in this conversation.