【问题标题】:How to get the coordinates of a drawn ploygon using angular google maps (AGM)如何使用角度谷歌地图(AGM)获取绘制多边形的坐标
【发布时间】:2019-10-21 17:26:59
【问题描述】:
【问题讨论】:
标签:
google-maps
angular-google-maps
【解决方案1】:
我通过听polygoncomplete事件知道了,从中可以得到多边形坐标如下图:
google.maps.event.addListener(drawingManager, 'polygoncomplete', function (polygon) {
const len = polygon.getPath().getLength();
const polyArrayLatLng = [];
for (let i = 0; i < len; i++) {
const vertex = polygon.getPath().getAt(i);
const vertexLatLng = {lat: vertex.lat(), lng: vertex.lng()};
polyArrayLatLng.push(vertexLatLng);
}
// the last point of polygon should be always the same as the first point (math rule)
polyArrayLatLng.push(polyArrayLatLng[0]);
console.log('coordinates', polyArrayLatLng);
});
stackblitz,参考:
google maps documentation