react-native-location not updating with latest location on android - always return the cache location

951 Views Asked by At

react native package - https://www.npmjs.com/package/react-native-location

location is not updating on android. It always return the cache location. But once we re-install / clear cache the app it will take the latest location. Works fine on ios.

const getCurrentLocation = async (callback) => {
  RNLocation.configure({
    distanceFilter: 10,
    desiredAccuracy: {
      ios: 'best',
      android: 'highAccuracy',
    },
    androidProvider: 'auto',
  });
  const location = await RNLocation.getLatestLocation({ timeout: 5000 });
  callback(location);
};

...

const hasPermission = await RNLocation.checkPermission({
    ios: 'whenInUse',
    android: {
      detail: 'coarse',
      rationale: {
        title: strings.enableLocationMessage,
        message: strings.enableLocationMessage,
        buttonPositive: strings.ok,
        buttonNegative: strings.cancel,
      },
    },
  });
1

There are 1 best solutions below

1
On

Same issue happened to me and couldn't solve after many hours. At the end, I decided to go with react-native-get-location (https://www.npmjs.com/package/react-native-get-location) repository and it works fine as I wish.