0
我已经在地图上创建了一个矩形和一个用于bounds_changed
的侦听器。它调用一个方法来确定一个点是否在调整后的矩形内。但是,当我更改矩形的大小时,出现错误Cannot read property 'getLength' of undefined
。此错误来自containsLocation
的呼叫。谷歌地图API:确定点是否在内部形状
在我的初始化:
rectangle = new google.maps.Rectangle({
bounds: bounds,
editable: true,
draggable: true,
geodesic: true,
map: map
});
google.maps.event.addListener(rectangle , 'bounds_changed', isWithinPoly);
功能,以确定是否点落在调整矩形:
function isWithinPoly(){
console.log(rectangle);
var point = new google.maps.LatLng(51.331, 3.538);
var isWithinPolygon = google.maps.geometry.poly.containsLocation(point, rectangle);
console.log(isWithinPolygon);
}
谢谢!这样做了,你有链接到API文档中的位置吗?我找不到它。 – turbo2oh 2014-10-16 21:35:20
https://developers.google.com/maps/documentation/javascript/reference?hl=zh-CN&csw=1#LatLngBounds – 2014-10-16 21:35:58