作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 map 上创建了一个矩形以及 bounds_changed
的监听器。它调用一个方法来确定一个点是否在调整后的矩形内。但是,当我更改矩形的大小时,我收到错误无法读取未定义的属性“getLength”
。此错误来自对 containsLocation
的调用。
在我的初始化中:
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);
}
最佳答案
containsLocation
需要一个多边形作为参数,而不是一个矩形。
对于矩形,请使用边界的方法contains
:
var isWithinRectangle = rectangle.getBounds().contains(point);
关于javascript - 谷歌地图 API : determine if point is inside shape,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26413963/
leaflet:一个开源并且对移动端友好的交互式地图 JavaScript 库 中文文档: https://leafletjs.cn/reference.html 官网(英文): ht
我是一名优秀的程序员,十分优秀!