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

孤人 提交于 2019-12-28 05:55:46

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/14407451/how-to-get-point-coordinates-of-a-modified-drawingmanager-shape-googlemaps-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!