A question about expo-location (the getCurrentPositionAsync({}) part)

Viewed 183

I hope you are doing well and safe. My question is very simple. I'm using EXPO-CLI to create a geolocation system tracker, so I was wondering if the getCurrentPositionAsync() gives me real-time data or I need to do something to make it update automatically.

to be more specific this my code you can have a look :

export default function Offres({ navigation }: { navigation: any }) {
  //STATE FOR GEOLOCATION
  const [location, setLocation] = useState<any | null>(null);
  const [hasPermission, setHasPermission] = useState<any | null>(null);
  //GEOLOCATION EFFECT
  React.useEffect(() => {
    (async () => {
      //PERMISSION INTERFACE
      const { status } = await Location.requestBackgroundPermissionsAsync();
      //GRANTED MEANS ACCEPTED
      setHasPermission(status === "granted");
      //GET USER LOCATION
      let {coords} = await Location.getCurrentPositionAsync({});
      if (coords){
        const{latitude,longitude}=coords;
        let response = await Location.reverseGeocodeAsync({latitude,longitude});
        for(let item of response){
          let adress = `${item.name}, ${item.street}, ${item.postalCode}, ${item.city}, ${item.timezone}`;
          console.log(adress) 
        }
      }
      setLocation(coords);
    })();
  }, []);

  let text = "Waiting..";
  if (location) {
    //USER LOCATION SHOWCASED IN JSON FORMAT
    text = JSON.stringify(location);
    console.log(text)
  }

  if (hasPermission === null) {
    //BACKGROUND INTERFACE WHEN ASKING FOR PERMISSIONS
    return <PermissionInterface />;
  }
  if (hasPermission) {
    //OFFER SCREEN IT WILL SHOWN IF THE PERMISSION IS GRANTED
    return <OffreScreenComponent navigation={navigation} />;
  }
  return (
    //INTERFACE WILL SHOWN IF THE PERMISSION IS DENIED
    //TEXT IS FOR SHOWCASING USER LOCATION DATA
      <NoActiveLocation />
      
  );
}

I hope someone can answer my question. Thank you all in advance.

0 Answers
Related