这是我正在使用的代码的核心,我没有得到错误,但我没有看到矩形区域中的点。任何帮助将不胜感激:
`enter code here`/** @this {google.maps.Rectangle} */
function showNewRect(event) {
var ne = rectangle.getBounds().getNorthEast();
var sw = rectangle.getBounds().getSouthWest();
google.maps.event.addlistener(rectangle, "bounds_changed", function(){
document.getElementById("map-selected").innerHTML=rectangle.getBounds();
var rectA = (ne*sw);
})
}
function listSelected(){
var inside = $ .map(sites,function(s){
var d;
if ( ( (d = google.maps.geometry.poly.containsLocation( s.position )) <= rectA ) )
return s.location + ' ('+(Math.round(d/100)/10)+' km)';
$('#map-selected').html( inside.sort().join('') );
});
}
google.maps.event.addListener(drawingManager, 'rectanglecomplete', function( rectangle ) {
selectedArea = rectangle;
listSelected();
google.maps.event.addListener(rectangle, 'center_changed', listSelected);
google.maps.event.addListener(rectangle, 'bounds_changed', listSelected);I am working with the Google maps API and I have a map I am drawing on with a rectangle. I need to have a user draw the rectangle, and on the map there will be predefined locations, that when the rectangle crosses the locations there will be details of each location put into a list.
这是一个例子:
我有一个使用圆形绘制工具的例子,我可以正常工作,但矩形工具我无法识别地图上的点。
如何在页面上没有预定义的矩形的情况下检查这些点?
谢谢,
答案 0 :(得分:0)
当绘制Rectangle迭代位置并使用Rectangle的contains()
方法bounds
来测试LatLng是否在Rectangle的范围内