Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get point coordinates of a modified drawingManager shape? GoogleMaps API v3

I have this DrawingManager Object:

    drawingManager = new google.maps.drawing.DrawingManager({
      drawingMode: google.maps.drawing.OverlayType.POLYGON,
      markerOptions: {
        draggable: true
      },
      polylineOptions: {
        editable: true
      },
      polygonOptions: polyOptions,
      map: map
    });

And when a Polygon is completed I get their coords with:

    google.maps.event.addListener(drawingManager, 'polygoncomplete', function (polygon) {
        var coordinates = (polygon.getPath().getArray());
        console.log(coordinates);
      });

But if I change the polygon using DrawingManager obviously the shape will change, maybe adding more Points..
Then How can I get all Points with their coords after modify it and for example click a button to finish the edition?? Thanks in advance.

like image 717
chespinoza Avatar asked Jan 18 '13 20:01

chespinoza


People also ask

How the Google map application makes use of coordinate geometry in its functioning?

World coordinates in Google Maps are measured from the Mercator projection's origin (the northwest corner of the map at 180 degrees longitude and approximately 85 degrees latitude) and increase in the x direction towards the east (right) and increase in the y direction towards the south (down).

How do I create a geofence on Google Maps?

Plotting a Geofence on the map To plot a geofence on the map, all you require are, center coordinates of the circle (latitude, longitude) and radius of the circle. With a GoogleMap object reference, you can use the addCircle() function which expects CircleOptions() object as a parameter.


1 Answers

Ok having the answer on my second code:

var coordinates = (polygon.getPath().getArray());

Finally I got the last array with coordinates calling this code by adding a listener to call a function that get the array:

JS

function getCoordinates() {
    console.log(polygon.getPath().getArray());
}

google.maps.event.addDomListener(document.getElementById('CoordsButton'), 'click', getCoordinates);

HTML

<button id="CoordsButton">Coordinates</button>

Then when the button is clicked now I get the coords...

Thanks anyway

like image 112
chespinoza Avatar answered Oct 16 '22 22:10

chespinoza