gpt4 book ai didi

javascript - 将纬度、经度和 zoomLevel 转换为 latitudeDelta 和 longitudeDelta

转载 作者:数据小太阳 更新时间:2023-10-29 04:21:10 24 4
gpt4 key购买 nike

我有一个缩放级别zoom=Z和一个位置latitude=xlongitude=y,但我需要设置区域包含 latitudelongitudelatitudeDeltalongitudeDelta

我找到了图片

enter image description here

解释latitudeDeltalongitudeDelta的工作原理,以及公式

zoom = Math.round(Math.log(360 / region.longitudeDelta) / Math.LN2

但是如何将缩放级别 zoom=Z 转换为 latitudeDeltalongitudeDelta

我想我只需要设置 latitudeDeltalongitudeDelta 然后根据屏幕尺寸计算另一个值?

最佳答案

因此,根据 longitudeDeltazoom 公式,我们可以表达longitudeDelta 和一些基本的数学规则:

enter image description here

通过这种方式,我们将zoom 转换为longitudeDelta。要找到 latitudeDelta,有不同的方法。我更喜欢找到 longitudeDeltalatitudeDelta 之间的系数,无论缩放级别如何,它总是相同的。这是我写的示例代码。我省略了将缩放级别四舍五入为整数以表明计算是正确的。

// Initial values
var latitudeDelta = 0.004757;
var longitudeDelta = 0.006866;

var coef = latitudeDelta / longitudeDelta; // always the same no matter your zoom

// Find zoom level
var zoomLvlCalculated = calcZoom(longitudeDelta);
console.log(zoomLvlCalculated); // 15.678167523696594

// Find longitudeDelta based on the found zoom
var longitudeDeltaCalculated = calcLongitudeDelta(zoomLvlCalculated);
console.log(calcLongitudeDelta(zoomLvlCalculated));// 0.006865999999999988 which is the same like the initial longitudeDelta, if we omit the floating point calc difference

// Find the latitudeDelta with the coefficient
var latitudeDeltaCalculated = longitudeDeltaCalculated * coef;
console.log(latitudeDeltaCalculated); //0.004756999999999992 which is the same like the initial latitudeDelta, if we omit the floating point calc difference

function calcZoom(longitudeDelta) {
// Omit rounding intentionally for the example
return Math.log(360 / longitudeDelta) / Math.LN2;
}

function calcLongitudeDelta(zoom) {
var power = Math.log2(360) - zoom;
return Math.pow(2, power);
}

附言由于 Internet Explorer 不支持以 2 为基数的日志,您可以使用此公式以不同的基数 (e) 进行计算:

enter image description here

关于javascript - 将纬度、经度和 zoomLevel 转换为 latitudeDelta 和 longitudeDelta,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46861148/

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