如何使用 Google 地图几何库中的 containsLocation. [英] How to use containsLocation in Google maps geometry library.

查看:18
本文介绍了如何使用 Google 地图几何库中的 containsLocation.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use the containsLocation from the Google geometry library, but can't get it to work...

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

The Javascript console gives an error, but that points to a function in Google's lib. So I assume the problem should lie somewhere in this function.

推荐答案

好吧,笨蛋

将所有坐标用作数组是错误的,我不得不使用创建的多边形对象.

I was wrong using all the coords as an array, I had to use the created polygon object.

var polyOptions = {
 ...
}

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

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

这篇关于如何使用 Google 地图几何库中的 containsLocation.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆