javascript - 如果我只知道它的大小和东北点,如何绘制谷歌地图矩形

标签 javascript google-maps-api-3

要在谷歌地图中绘制一个矩形,我需要先知道西北点和东南点来构建 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/

相关文章:

javascript - 如何将所有参数作为集合传递给另一个函数而不是作为单个参数?

javascript - IE8 jQuery 淡入淡出

javascript - 使用 angular-google-maps 点击隐藏所有信息窗口

javascript - Google Maps API v3 信息窗口关闭事件/回调?

javascript - Google Maps API v3 热图错误 : "Cannot read property ' HeatmapLayer' of undefined"

javascript - 如何根据预先确定的约束值自定义热图颜色?

javascript - 实现像 jQuery 这样的可链接 JavaScript 框架的最直接方法是什么?

javascript - 如何使用javascript查找可被多个数字整除的数字

JavaScript + 递归函数返回未定义

google-maps-api-3 - 使用免费的 gmaps 帐户每秒可以执行多少个请求?