Open kamalpandey opened 3 years ago
follow
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,
},
);
};`
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, }, );
};`
What does getLocation() function actually do? Is it fetching current coordinate? Pls help, I faced the same issue above.
@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?