Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google maps 如何使用谷歌地图几何库中的ContainesLocation。_Google Maps_Google Maps Api 3 - Fatal编程技术网

Google maps 如何使用谷歌地图几何库中的ContainesLocation。

Google maps 如何使用谷歌地图几何库中的ContainesLocation。,google-maps,google-maps-api-3,Google Maps,Google Maps Api 3,我正在尝试使用Google geometry库中的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 goo

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

好了,愚蠢的我

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

var polyOptions = {
 ...
}

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

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

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


然后问题消失了。

当我这样做时,我得到了错误
对象[Object Object]没有方法“get”
我不确定,但我相信这是针对API版本2的。那时候真的很管用。。。