google-maps - 如何使用 Google map 几何库中的 containsLocation。

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

我正在尝试使用 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 库中的一个函数。所以我认为问题应该出在这个函数的某个地方。

最佳答案

好吧,愚蠢的我

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

var polyOptions = {
 ...
}

draw = new google.maps.Polygon(polyOptions);
draw.setMap(map);

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

关于google-maps - 如何使用 Google map 几何库中的 containsLocation。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10836559/

相关文章:

java - 安装 Google Maps SDK Beta 3.1.0 时出错 Could not filnd :places-map-sdk-3. 1.0-beta:

javascript - markerwithlabel.js(第三方)原始文件链接断开

javascript - 使谷歌地图跨越长页面

HTML 页面不显示谷歌地图

javascript - Angular 谷歌地图主 Controller 错误

google-maps - Google Maps API V3 Infobox.js 已删除

javascript - 将谷歌位置自动完成功能添加到列表项中新生成的输入中

javascript - Google map 标记出现在 native 页面链接上

css - 使用 SVG 和 CSS 创建直线和圆的交点

java - 无法解析方法 getMap()