我有以下代码的问题,在我的点从来没有找到一个点在多边形使用google.maps.geometry.poly.containsLocation。您可以看到完整的代码,并且在这里的多边形中确实有点http://htinteractive.com/crime_map_fairview.html但是在控制台中,您将看到根据containsLocation函数在多边形中没有找到任何点。
我觉得也许我没有把一个值正确地传递给containsLocation函数,但到目前为止,我在文档中发现这似乎是正确的。
var myLatlng = new google.maps.LatLng(lat,lon);
fairview = [
new google.maps.LatLng(39.161536, -86.535107),
new google.maps.LatLng(39.17885, -86.534825),
new google.maps.LatLng(39.179068, -86.547164),
new google.maps.LatLng(39.180989, -86.551803),
new google.maps.LatLng(39.181546, -86.556001),
new google.maps.LatLng(39.170956, -86.569335),
new google.maps.LatLng(39.158487, -86.570365),
new google.maps.LatLng(39.161482, -86.566674),
new google.maps.LatLng(39.157156, -86.559807),
new google.maps.LatLng(39.160084, -86.553961),
new google.maps.LatLng(39.160317, -86.550700),
new google.maps.LatLng(39.160733, -86.548464),
new google.maps.LatLng(39.161482, -86.546172),
new google.maps.LatLng(39.161536, -86.535107)
];
var pv = new google.maps.Polygon(fairview);
if (google.maps.geometry.poly.containsLocation(myLatlng, pv)) {
console.log("Location Found in Polygon!!!!! " + myLatlng.lat() + " " + myLatlng.lng());
} else {
console.log(":( " + myLatlng.lat() + " " + myLatlng.lng());
}
正如Molle博士指出的那样,我的多边形实例化错误。
var pv = new google.maps.Polygon({path:fairview});