使用 Google maps API V3,特别是使用绘图工具(仅启用矩形),如下所示:
https://developers.google.com/maps/documentation/javascript/overlays#drawing_tools
但我有以下问题,
- 我可以(如果是这样的话),通过用户单击同一页面上的链接的动作,检索多边形左上角和右下角的纬度,经度,并发送到一个网址,即;
使用 Google maps API V3,特别是使用绘图工具(仅启用矩形),如下所示:
https://developers.google.com/maps/documentation/javascript/overlays#drawing_tools
但我有以下问题,
检索矩形
检索用户绘制的矩形的一种方法是使用绘图事件:
var rectangle;
google.maps.event.addListener(drawingManager, 'rectanglecomplete', function(newRect) {
rectangle = newRect;
});
每当用户绘制一个矩形时,它都会将 Rectangle 覆盖对象分配给rectangle
全局变量。
提取有关矩形的信息
该类有一个方法,google.maps.Rectangle
该getBounds()
方法返回一个LatLngBounds
对象。可以使用getNorthEast()
和getSouthWest()
方法推导出左上角和右下角坐标。
您可以将onclick
事件绑定到链接。click 事件处理程序可能如下所示:
function clickEventHandler(event) {
// check if the rectangle has been assigned
if (rectangle == undefined) {
alert('No rectangles have been drawn yet!');
return;
}
// obtain the bounds and corner coordinates of the rectangle
var rectangleBounds = rectangle.getBounds();
var northEast = rectangleBounds.getNorthEast();
var southWest = rectangleBounds.getSouthWest();
// deduce the top-left and bottom-right corner coordinates
var topLeft = new google.maps.LatLng(northEast.lat(), southWest.lng());
var bottomRight = new google.maps.LatLng(southWest.lat(), northEast.lng());
// Now that you have the coordinates, all you have to do is use an AJAX
// technique of your choice to send the HTTP request to script.php.
// ...
}
进一步阅读: