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
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
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); does the magic.
<MapView
onRegionChangeComplete={async (region) => {
const coords = await ref?.current?.getCamera();
console.log('coords', coords.zoom);
}}
ref={ref} />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With