要在谷歌地图中绘制一个矩形,我需要先知道西北点和东南点来构建 LatLngbounds。
在我的情况下,我想绘制一个具有特定西北点和尺寸(比如 100 米宽和 100 米高)的矩形。我不知道最南端。
我害怕几何学和地质学。我知道东南可以从一些公式中得出。只是想知道是否有 api 或简单的方法来做到这一点?
最佳答案
你可以这样写一个函数:
// Given the LatLng of a northwest corner, and the number of meters to
// measure east and south, return the LatLngBounds for that rectangle
function makeBounds( nw, metersEast, metersSouth ) {
var ne = google.maps.geometry.spherical.computeOffset(
nw, metersEast, 90
);
var sw = google.maps.geometry.spherical.computeOffset(
nw, metersSouth, 180
);
return new google.maps.LatLngBounds( sw, ne );
}
这是一个 working example .
关于javascript - 如果我只知道它的大小和东北点,如何绘制谷歌地图矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15969043/