扩展多边形的界限 - Google Maps V3 Javascript API [英] Extending Bounds For Polygons -- Google Maps V3 Javascript API
问题描述
我的目标是检测一个标记是否在一个奇怪形状的多边形对象内(想象25个不同的点)。我注意到LatLngBounds属性只包含两组LatLng,即使在使用.extend函数之后,例如:
((34.347971491244955,-122.40966796875),( 34.829586636768205,-120.9649658203125))
这是正常的行为吗?
下面的代码是我正在构建的程序,但包含我如何使用扩展功能的相关信息。如果我不能使用.extend()和.contains()的组合,那么有没有人知道如何检测一个标记是否在一个形状奇怪的多边形内?
var coordinates =(polygon.getPath()。getArray()); //获得
var bounds = new google.maps.LatLngBounds();
函数extendBounds(bounds,coordinates){
for(b坐标){
bounds.extend(coordinates [b]);
};
console.log(bounds.toString());
};
多边形的边界是一个矩形。如果要检测多边形中是否有标记,请使用 google.maps.geometry.poly中的containsLocation函数命名空间,将多边形和标记的位置传递给它
containsLocation(point:LatLng,polygon:Polygon)布尔|计算给定点是否位于指定的多边形内。
My goal is to detect if a marker is within an oddly shaped polygon object (think 25 different points). I have noticed that the LatLngBounds property, only contains two sets of LatLngs, even after using the .extend function, for example:
((34.347971491244955, -122.40966796875), (34.829586636768205, -120.9649658203125))
Is this normal behavior?
The code below is a tiny snippet of the program I am building, but contains the relevant information for how I am using the extend function. Does anyone have any idea how to detect if a marker is within an oddly shaped polygon, if I can't use a combination of .extend() and .contains()?
var coordinates = (polygon.getPath().getArray()); //get
var bounds = new google.maps.LatLngBounds();
function extendBounds(bounds, coordinates) {
for (b in coordinates) {
bounds.extend(coordinates[b]);
};
console.log(bounds.toString());
};
The bounds of a polygon is a rectangle. If you want to detect if a marker is in the polygon use the containsLocation function in google.maps.geometry.poly namespace, passing it the polygon and the position of the marker
containsLocation(point:LatLng, polygon:Polygon) | boolean | Computes whether the given point lies inside the specified polygon.
这篇关于扩展多边形的界限 - Google Maps V3 Javascript API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!