Shevon Soyza
Shevon Soyza

Reputation: 11

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

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,
      },
    },
  });

Upvotes: 0

Views: 1317

Answers (1)

Eray KIZILTAŞ
Eray KIZILTAŞ

Reputation: 61

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.

Upvotes: 1

Related Questions