react-native-geolocation-service icon indicating copy to clipboard operation
react-native-geolocation-service copied to clipboard

IOS watchPosition triggered only once. [Help Needed]

Open kamalpandey opened this issue 4 years ago • 3 comments

@Agontuk I am using the example code. In Android when I press Start Observing button it is working fine but in IOS it is triggered only once.

Am I missing some configuration or this is valid?

Screen Shot 2021-09-04 at 17 52 57

kamalpandey avatar Sep 04 '21 12:09 kamalpandey

follow

gitmazzio avatar Sep 17 '21 17:09 gitmazzio

Hey, buddy. Found how you can adapt to this if you have the location only come once when watchPosition. Use setTimeout in parallel with this method, which will get the location from getCurrentPosition and everything will work as it should.

`const getLocationUpdates = async () => { const hasPermission = await hasLocationPermission();

if (!hasPermission) {
  return;
}

if (Platform.OS === 'android') {
  await startForegroundService();
}

if (Platform.OS === 'ios') {
  intervalId.current = setInterval(() => {
    getLocation();
  }, 5000);
}

watchId.current = Geolocation.watchPosition(
  position => {
    setLocation(position);
    console.log(position);
  },
  error => {
    setLocation(null);
    console.log(error);
  },
  {
    accuracy: {
      android: 'high',
      ios: 'best',
    },
    enableHighAccuracy: true,
    distanceFilter: 0,
    interval: 5000,
    fastestInterval: 2000,
    forceRequestLocation: true,
    forceLocationManager: true,
    showLocationDialog: true,
    useSignificantChanges: true,
  },
);

};`

yaroslav-vasilyev avatar Feb 13 '24 13:02 yaroslav-vasilyev