How do I capture point locations of Polygon with Google Maps API?

后端 未结 1 918
忘掉有多难
忘掉有多难 2021-01-19 01:10

Using the Google Maps API Drawing Manager, I want to collect the location of each point in the polygon that is drawn by a user.

I know there is a getPath()

相关标签:
1条回答
  • 2021-01-19 01:59

    use it inside the polygoncomplete-callback.

    example:

     google.maps.event.addListener(drawingManager, 'polygoncomplete', function(polygon) {
        drawingManager.setDrawingMode(null);
        var arr=[];
        polygon.getPath().forEach(function(latLng){arr.push(latLng.toString());})
        alert(arr.join(',\n'));
    });
    

    it iterates over the path(using the forEach-method of a google.maps.MVCArray) and populates another array with the string-representations of the LatLng's

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题