【问题标题】:How to get the coordinates of a drawn ploygon using angular google maps (AGM)如何使用角度谷歌地图(AGM)获取绘制多边形的坐标
【发布时间】:2019-10-21 17:26:59
【问题描述】:

我正在开发一个功能,用户应该能够绘制polygon 并将polygon coordinates 存储到系统中,以便稍后在地图上显示它。 我在这里实现了绘图功能: https://stackblitz.com/edit/angular-ptjb9t?file=src%2Fapp%2Fapp.component.html

但是我怎样才能得到那个多边形的坐标“points(lat,lng)”呢?

谢谢

【问题讨论】:

    标签: 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

    【讨论】:

      猜你喜欢
      • 2017-12-16
      • 1970-01-01
      • 1970-01-01
      • 2016-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      相关资源
      最近更新 更多