Jam*_*een 8 javascript google-maps latitude-longitude reactjs react-native
我有一个缩放级别zoom=Z和位置latitude=x,longitude=y但我需要设置与区域latitude,longitude,latitudeDelta和longitudeDelta.
我找到了这张照片
解释如何latitudeDelta和longitudeDelta工作,以及公式
zoom = Math.round(Math.log(360 / region.longitudeDelta) / Math.LN2
Run Code Online (Sandbox Code Playgroud)
但是,我怎么能缩放级别转换zoom=Z到latitudeDelta和longitudeDelta?
我猜想,我只需要设置两种latitudeDelta或longitudeDelta再计算从与屏幕尺寸的其他值?
zoom因此,有了依赖于 的公式,我们可以用一些基本的数学规则来longitudeDelta表达
:longitudeDelta
这样我们就可以将 转换zoom为longitudeDelta. 要找到latitudeDelta有不同的方法。longitudeDelta我更喜欢找到和 之间的系数latitudeDelta,无论缩放级别如何,该系数始终相同。这是我编写的示例代码。我省略了将缩放级别舍入为整数的操作,以表明计算是正确的。
// 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);
}
Run Code Online (Sandbox Code Playgroud)
PS 由于 Internet Explorer 不支持以 2 为底的对数,您可以使用此公式以不同的底数 (e) 进行计算:
| 归档时间: |
|
| 查看次数: |
771 次 |
| 最近记录: |