javascript 获取多边形中每个点的纬度和经度 - Google Maps API v3

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22696733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 23:35:48  来源:igfitidea点击:

Get lat and lon for each point in polygon - Google Maps API v3

javascriptjqueryapimaps

提问by user3469947

I found an answer for how to get the latitude and longitude for each point of the polygon here:

我在这里找到了如何获取多边形每个点的纬度和经度的答案:

Polygon Drawing and Getting Coordinates with Google Map API v3

使用 Google Map API v3 绘制多边形和获取坐标

This appeared to work when I implemented it, however is no longer working, and I get the error:

这在我实施时似乎有效,但不再有效,并且出现错误:

"Error: TypeError: polygon.overlay.latLngs.b is undefined"

“错误:类型错误:polygon.overlay.latLngs.b 未定义”

This is my code:

这是我的代码:

function polygonPoints(polygon) {
    var polygonPointsArray = [];

    $.each(polygon.overlay.latLngs.b[0].b, function(key, latlng){
            var lat = latlng.d;
            var lon = latlng.e;

            polygonPointsArray.push(lat+' '+lon); //do something with the coordinates
    });
}

Any help would be greatly appreciated.

任何帮助将不胜感激。

Thanks

谢谢

Matt

马特

采纳答案by Anto Jurkovi?

That failed because polygon internal structure changed which happens from time to time.

那失败了,因为多边形内部结构不时发生变化。

How to get latitude and longitude of polygon points is described in this google example.

这个谷歌示例中描述了如何获取多边形点的纬度和经度。

回答by Dylan Hamilton-Foster

I had this problem as well - the quick fix for me was to change

我也有这个问题 - 对我来说快速解决是改变

$.each(polygon.overlay.latLngs.b[0].b, function(key, latlng){

to

$.each(polygon.overlay.latLngs.j[0].j, function(key, latlng){