gpt4 book ai didi

javascript - 如何获取map.getBounds()作为4个 float 的列表?

转载 作者:行者123 更新时间:2023-12-02 14:29:00 25 4
gpt4 key购买 nike

我想以 4 个 float 的列表形式获取 map 边界的坐标(即纬度/经度坐标中的两个点)。

这个(Google map 未记录的功能)直到几天前还可以工作:

var b = map.getBounds();
var bounds = [b.H.H, b.H.j, b.j.j, b.j.H];

它不再起作用了。如何获得这4个 float ?

最佳答案

function getRectFromBounds(bounds) {
var ne = bounds.getNorthEast();
var sw = bounds.getSouthWest();
return [ne.lat(), ne.lng(), sw.lat(), sw.lng()];
};

var rect = getRectFromBounds(map.getBounds());

您可以扩展 LatLngBounds 并创建一个实用函数来返回此数组,例如 map.getBounds().toRect()

关于javascript - 如何获取map.getBounds()作为4个 float 的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37997734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com