the execution time of watchPosition and the expected non-conformance
Your Environment
- Plugin version: 4.12.1
- Platform: iOS or Android : iOS
- OS version: 16.1.1
- Device manufacturer / model: iPhone 14
- React Native version (
react-native -v): 0.68.7 - Plugin config
this.geolocation.ready({
debug: false,
maxDaysToPersist: 2,
stationaryRadius: 100,
stopOnTerminate: false,
allowIdenticalLocations: false,
desiredAccuracy: this.geolocation.DESIRED_ACCURACY_HIGH,
notification: {
title:
'The delivery task starts and is using the current location to locate',
},
disableLocationAuthorizationAlert: true,
locationAuthorizationRequest: 'Any',
locationAuthorizationAlert: {
titleWhenNotEnabled: 'Location services are not enabled',
titleWhenOff: 'Location services are not enabled',
instructions:
"To ensure best app experience, please enable 'Always' location permissions in device settings.",
cancelButton: 'Cancel',
settingsButton: 'Settings',
},
backgroundPermissionRationale: {
title: 'Update location settings',
message:
'Allow us to always access your location so that we can provide accurate distribution of delivery orders, delivery routes and monitor your safety, improve work efficiency',
positiveAction: 'Change to {backgroundPermissionOptionLabel}',
negativeAction: 'Cancel',
},
});
Expected Behavior
watchPosition is executed every ten seconds.
watchPosition(
async (location: Location) => {
console.log(
'Trigger event log:',
getDevicezoneDateTime('YYYY-MM-DD HH:mm:ss'),
);
...
},
(errorCode: LocationError) => {
...
},
{
interval: 10000,
},
)
Actual Behavior
Execute once in twenty seconds
The first :
LOG Trigger event log: 2023-08-08 17:11:09
LOG Trigger event log: 2023-08-08 17:11:29
LOG Trigger event log: 2023-08-08 17:11:49
Second time :
LOG Trigger event log: 2023-08-08 17:12:09
LOG Trigger event log: 2023-08-08 17:12:29
LOG Trigger event log: 2023-08-08 17:12:49
Steps to Reproduce
- Open the app
- Click button to trigger watchPosition
Context
Debug logs
Logs
PASTE_YOUR_LOGS_HERE
What are you using .watchPosition for?
What are you using .watchPosition for?
Timing use . watchPosition to obtain the latitude and longitude of the current device.
Yes, that’s obvious. But why specifically .watchPosition? That method is meant for short periods of time while your app is in the foreground. You do not need to use that method. Do not use this method for long-term tracking in the background.
All you need to do to use this plug-in is call .start().
See wiki Philosophy of Operation.
Yes, that’s obvious. But why specifically .watchPosition? That method is meant for short periods of time while your app is in the foreground. You do not need to use that method. Do not use this method for long-term tracking in the background.
All you need to do to use this plug-in is call .start().
See wiki Philosophy of Operation.
I called the start method before calling the watchPosition method.
In fact, I want to know why setting 10s execution once will become 20s.
Why specifically are you using .watchPosition? I want people to avoid using this method.
I have such needs here:
Whether it is the foreground or the background, record longitude and latitude once in 10 seconds and submit api once in 1 minute.
.watchPosition is not designed for long-term use in the background.
call .changePace(true) and implement your own timer to call .getCurrentPosition
.watchPosition is not designed for long-term use in the background.
call .changePace(true) and implement your own timer to call .getCurrentPosition
OK, thank you, I'll continue to study and see.
@christocracy I'm facing with same issue. If I passed interval: 1000 location is triggered every ~10s, if I passed interval: 10000 location is triggered every ~20s. Looks like a bug.
You are not providing any information (plug-in version, platform, device model, etc).
Your Environment
- Plugin version: 4.12.1
- Platform: iOS
- OS version: 16
- Device manufacturer / model: iPhone X
- React Native version (
react-native -v): 0.72.0 - Plugin config
{
startOnBoot: true,
stopOnTerminate: false,
enableHeadless: true,
autoSync: false,
url: '...',
showsBackgroundLocationIndicator: false,
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
persistMode: BackgroundGeolocation.PERSIST_MODE_ALL,
distanceFilter: 10,
disableLocationAuthorizationAlert: true,
preventSuspend: false,
useSignificantChangesOnly: false,
logLevel: BackgroundGeolocation.LOG_LEVEL_OFF,
}
Code
BackgroundGeolocation.watchPosition(
location => {
console.log(location);
},
errorCode => {
console.error('watchPosition', errorCode);
},
{
interval: 1000,
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
},
);
Testing in the simulator is the most accurate way to test timing since it isn't affected by the environment. The timing of interval (using stopwatch) is correct and exact. There is no guarantee that watchPosition on an actual device will return a location at the exact interval, particularly while indoors, where GPS doesn't work.
interval: 1000
interval: 5000
interval: 10000
I understand that intervals could be various, but difference in 10 seconds is too much when interval is 1 second. iPhone simulator has the same behaviour and it doesn't few cases, it works like if interval was set 10 seconds instead of 1 second
Did you see my stop-watch images above? They are perfect.
Yes. Looks like side effects produce this bug. Because I run watchPosition in clear environment and it works perfectly
What do you mean by "side-effects"?
I don't agree this is a bug.
What are you using .watchPosition for?
"side effects" is my code.
I'm using it for foreground location updates to display user on map.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.