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

Javascript 如果我只知道谷歌地图矩形的大小和东北点,如何绘制它,javascript,google-maps-api-3,Javascript,Google Maps Api 3,要在谷歌地图中绘制一个矩形,我需要知道西北和东南点,以便首先构建一个LatLngbounds 在我的情况下,我想画一个具有特定西北点和大小(例如100米宽和100米高)的矩形。我不知道最南边的地方 我害怕几何和地质学。我知道东南方向可以从一些公式中推导出来。只想知道是否有api或简单的方法可以做到这一点?请参见几何体库中的 计算偏移量(起点:板条、距离:编号、航向:编号、半径?:编号) 类似(未经测试): 确保包含您可以编写如下函数: // Given the LatLng of a north

要在谷歌地图中绘制一个矩形,我需要知道西北和东南点,以便首先构建一个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 );
}
这是一个例子

// 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 );
}