How to set zoom level in google map according to miles in react native?

Viewed 1855

I have react native application using react-native-maps,in which there is a feature to display near by users based on radius chosen by user that works fine using geocode. but I am facing problem to set zoom level of Map based on user radius? if user selects maximum meter of radius then map should display whole world? How can I achieve this? to set zoom level dynamically based on radius chosen by user?

to set radius used react-native-slider, How can set zoom level on slide of slider?

2 Answers
import { Dimensions} from 'react-native';
let {width, height} = Dimensions.get('window');
const ASPECT_RATIO = width / height;
const LATITUDE_DELTA = 1; //Increase or decrease the zoom level dynamically
const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIO;

<MapView
 region={{
  latitude: currentLocation.latitude,
  longitude: currentLocation.longitude,
  latitudeDelta: LATITUDE_DELTA,
  longitudeDelta: LONGITUDE_DELTA,
 }}>
      initialRegion:{
        latitude: parseFloat(28.999),
        longitude: parseFloat(28.999),
        latitudeDelta: 0.3822,
        longitudeDelta: Dimensions.get('window').width / Dimensions.get('window').height,
      }
Related