Please provide the following:
- SDK Version: 37.0.0
- Platforms(Android/iOS/web/all): Android / iOS
I’m in need of your advices and help. I develop an application (intended to use in both Android and iOS), using Expo CLI with React Native. I am using expo-location to get the device’s location, and even though I have set the interval to a certain time in startLocationUpdatesAsync, it doesn’t fire in the given interval, but mostly in double or triple the time needed when the phone is locked. However, if I do use my phone, the intervals are better and more consistent. Is there any way to fix it? I have attached below the code block for reference:
const options_updates = {
accuracy: Location.Accuracy.BestForNavigation, //accuracy must be best for navigation,
timeInterval: 300000, //interval for android
foregroundService: { //foreground serrvice to keep it running in background on android
notificationTitle: "Always with you", //notification for the background location - title
notificationBody: "I am following you" //notification for the background location - body
},
showsBackgroundLocationIndicator: true, //changes status bar appearance on ios
pausesUpdatesAutomatically: false, //will not pause location updates on ios
}
TaskManager.defineTask(TASKNAME_BACKGROUND, ({ data: { locations }, error }) => { //defines the background location task
console.log("task run!"); //logs that the task runs
if (error) { //if we get an error
console.log("Got error while sending", error); //logs the error
Location.stopLocationUpdatesAsync(TASKNAME_BACKGROUND);//cleans up the task
return;
}
console.log('Received new locations on ' + locations[0].coords.latitude + ', ' + locations[0].coords.longitude, "timestamp: " + timestamp_get()); //logs the coordinates
});
Location.startLocationUpdatesAsync(TASKNAME_BACKGROUND, options_updates); //starts background task to retrieve location
For those of you who will probably ask why I didn’t use deferredUpdatesInterval, it is because it stops working after some time, probably because of the same reason. The second problem with it, is that it forgets I set this option once I unlock my phone.