Javascript 将纬度、经度和zoomLevel转换为latitudeDelta和LongtudeDelta

Javascript 将纬度、经度和zoomLevel转换为latitudeDelta和LongtudeDelta,javascript,reactjs,google-maps,react-native,latitude-longitude,Javascript,Reactjs,Google Maps,React Native,Latitude Longitude,我有一个缩放级别zoom=Z和一个位置纬度=x,经度=y,但我需要设置带有纬度,经度,纬度和经度的区域 我找到了图像 解释latitudelta和longitudeDelta的工作原理以及公式 zoom = Math.round(Math.log(360 / region.longitudeDelta) / Math.LN2 但是如何将缩放级别zoom=Z转换为latitudelta和longitudeDelta 我想我只需要设置latitudelta或longitudeDelta,然后根据

我有一个缩放级别
zoom=Z
和一个位置
纬度=x
经度=y
,但我需要设置带有
纬度
经度
纬度
经度
的区域

我找到了图像

解释
latitudelta
longitudeDelta
的工作原理以及公式

zoom = Math.round(Math.log(360 / region.longitudeDelta) / Math.LN2
但是如何将缩放级别
zoom=Z
转换为
latitudelta
longitudeDelta


我想我只需要设置
latitudelta
longitudeDelta
,然后根据屏幕大小计算其他值?

因此,根据
longitudeDelta
我们可以表示
longitudeDelta
具有一些基本的数学规则:

通过这种方式,我们将
缩放
转换为
纵向德尔塔
。 要查找
latitudelta
,有不同的方法。我更喜欢在
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);
}
注意:由于Internet Explorer不支持以2为基数的日志,您可以使用此公式以不同的基数(e)计算:


我知道这很旧,但您可以从onRegionChange()传递的Region属性中获取latDelta和longDelta

const[latDelta,setlatDelta]=useState(“”)//LattudeDelta中存储的LattudeDelta
const[lngDelta,setlngDelta]=使用状态(“”)//储存在lngDelta中的longitudeDelta
常量getCoordinates=(区域)=>{
setlatDelta(Region.latitudeDelta);//将变量存储到latDelta中
setLngDelta(Region.longitudeDelta);//将变量存储到lngDelta中
} 
onRegionChange={(区域)=>getCoordinates(区域);}

幸运吗?我以为缩放级别会有相应的纬度和经度增量常数。我错了吗?
const [latDelta, setlatDelta] = useState('');  //latitudeDelta stored in latDelta
const [lngDelta, setlngDelta] = useState('');  //longitudeDelta stored in lngDelta


const getCoordinates = (Region) => {
  
  setlatDelta(Region.latitudeDelta);  //store varable into latDelta
  setLngDelta(Region.longitudeDelta); //store variable into lngDelta

} 

<MapView>
  onRegionChange = {(Region) => getCoordinates(Region);}
</MapView>