[英]how to get zoom level in react native map
I'm trying to calculate the zoom level when user zoom in or out,我正在尝试计算用户放大或缩小时的缩放级别,
I find that react native maps has a onRegionChange which has longiture, latitude, longitude delta and latitude delta which (I guess) could be used to compute zoom level我发现反应原生地图有一个 onRegionChange 有经度,纬度,经度增量和纬度增量(我猜)可以用来计算缩放级别
from this response I tried this way:从这个回应我试过这样:
Math.round(Math.log(360 / this.state.longitudeDelta) / Math.LN2);
but it return a big number (which is not the zoom level).但它返回一个大数字(这不是缩放级别)。
Write a function like below in the onRegionChangeComplete
prop of react-native-map在 react-native-map 的
onRegionChangeComplete
编写如下函数
changeRegion = debounce(async region => {
console.log(
Math.log2(360 * (metrics.screenWidth / 256 / region.longitudeDelta)) + 1
);
}, 1000);
or to be specific , Math.log2(360 * (metrics.screenWidth / 256 / region.longitudeDelta)) + 1);
或者具体来说,
Math.log2(360 * (metrics.screenWidth / 256 / region.longitudeDelta)) + 1);
does the magic.魔法。
<MapView onRegionChangeComplete={async (region) => { const coords = await ref?.current?.getCamera(); console.log('coords', coords.zoom); }} ref={ref} />
log2(360 * ((screenWidth/256) / region.longitudeDelta)) + 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.