michalchudziak / react-native-geolocation

Geolocation APIs for React Native
MIT License
1.29k stars 224 forks source link

Cannot getting location every time in iOS #323

Open muslimmuda15 opened 1 month ago

muslimmuda15 commented 1 month ago

Sometimes, my app want to getting current location to user but not every time is successful.

Geolocation.getCurrentPosition(
      ({ coords: { latitude, longitude, accuracy } }) => {
        setUserLoc({
          ...userloc,
          latitude,
          longitude,
          accuracy,
        });

        Geolocation.watchPosition(
          ({ coords: { latitude, longitude, accuracy } }) => {
            setUserLoc({
              ...userloc,
              latitude,
              longitude,
              accuracy,
            });
          },
          error => {
            console.log('watch user position: ', error);
            sendToSlack(
              'Error Watching Location on _getCurrentPosition App.js',
              error,
            );
          },
          {
            enableHighAccuracy: true,
            timeout: 20000,
            maximumAge: 5000,
            distanceFilter: 10,
          },
        );
        setTimeout(() => Geolocation.clearWatch(), 300000);
      },
      error => {
        console.log('error accessing location: ', error);
      },
      { enableHighAccuracy: true, timeout: 20000, maximumAge: 5000 },
    );

I think it will be success in first time only. another time it will be error like this:

{
    "code": 3,
    "message": "Unable to fetch location within 20.0s.",
    "PERMISSION_DENIED": 1,
    "POSITION_UNAVAILABLE": 2,
    "TIMEOUT": 3
}

I have set NSLocationAlwaysUsageDescription and NSLocationAlwaysAndWhenInUseUsageDescription in my info.plist Please help

atlasagencyca commented 1 month ago

Im having the same issue i have to close and reopen the app completely for it to work again

gulsher7 commented 1 month ago

++

CostasCF commented 1 month ago

++