【问题标题】:How to use containsLocation in Google maps geometry library.如何在谷歌地图几何库中使用 containsLocation。
【发布时间】:2012-05-31 15:26:44
【问题描述】:

我正在尝试使用 Google 几何库中的 containsLocation,但无法使用...

var point = new google.maps.LatLng(51.331, 3.538);
var poly = [
 new google.maps.LatLng(51.401818509550615, 3.547626782103622),
 new google.maps.LatLng(51.397574277049365, 3.563607598960424),
 new google.maps.LatLng(51.398540111384975, 3.567880788749134),
 ... // it is a lot bigger
];

if(google.maps.geometry.poly.containsLocation(point, poly) == true) {
 alert("yes");
}

Javascript 控制台给出了一个错误,但它指向了 Google 库中的一个函数。所以我认为问题应该出在这个函数的某个地方。

【问题讨论】:

    标签: google-maps google-maps-api-3


    【解决方案1】:

    好吧,我傻了

    将所有坐标用作数组是错误的,我必须使用创建的多边形对象。

    var polyOptions = {
     ...
    }
    
    draw = new google.maps.Polygon(polyOptions);
    draw.setMap(map);
    
    if(google.maps.geometry.poly.containsLocation(point, draw) == true) {
     alert("yes");
    }
    

    【讨论】:

    • 当我这样做时,我收到错误Object [object Object] has no method 'get'
    • 我不确定,但我相信这是针对 API 版本 2 的。当时它确实有效...
    【解决方案2】:

    我有同样的问题([object Object]),我可以解决这样创建多边形变量的问题: draw = new google.maps.Polygon({paths:polyOptions});

    然后问题就消失了。

    【讨论】:

      猜你喜欢
      • 2020-08-28
      • 1970-01-01
      • 2016-09-11
      • 1970-01-01
      • 2014-05-03
      • 1970-01-01
      • 2015-04-07
      • 1970-01-01
      • 2011-09-12
      相关资源
      最近更新 更多