Getting duplicate coordinates while using getCurrentPosition method
Your Environment
- Plugin version: 4.14.5
- Platform: Android
- OS version:14
- Device manufacturer / model:Google Pexel_3a emulator
- React Native version (
react-native -v):0.67.5 - Plugin config
const st = await BackgroundGeolocation.ready({
distanceFilter: 50,
debug: true,
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
locationUpdateInterval: 30000,
stopOnTerminate: false,
isMoving: true,
foregroundService: false,
enableHeadless: false,
persistMode:BackgroundGeolocation.PERSIST_MODE_NONE,
})
for (let i = 0; BackgroundService.isRunning(); i++) {
BackgroundGeolocation.getCurrentPosition({
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
samples:0,
persist: false,
}).then(async (pos) => {
let position = {
longitude: pos.coords.longitude,
latitude: pos.coords.latitude,
accuracy: pos.coords.accuracy,
speed: pos.coords.speed,
time: pos.timestamp,
provider: pos.provider,
}
console.log(position)
}
).catch(async er => {
console.log(er,"error");
})
await sleep(delay);
}
Expected Behavior
It should give new location every 30 sec .
Actual Behavior
It is giving locations every 30 sec but new location every 10 mins and remaining all are duplicate coordinates
Steps to Reproduce
Context
I'm using a library called react-native-background-action for background services and within that i'm using this library geolocation's getCurrentPosition method to fetch coordinate every 30 sec.
Debug logs
Logs
https://docs.google.com/spreadsheets/d/1b9PEUp3HbIx3_0RuaXnFAP_BDMNghIzIjwPvBbLKwCM/edit#gid=0
Are you observing the plug-in native logs?
See wiki "Debugging" and learn to observe the logs.
samples:0,
What do you think that does?
Are you observing the plug-in native logs?
See wiki "Debugging" and learn to observe the logs.
During testing with real device i got this and one interesting thing is i did multiple test and results are below I conducted tests on 02/12/2023 and 04/12/2023.
Case 01 (02/12/2023): I activated both my App and the library demo application on the same device. User took a complex route.
Observations:
- Both applications calculated distances based on the Odometer.
- My app fetched coordinates every 30 seconds without fail.
- Both applications ran continuously for over 8 hours.
Odometer reading: 43.07 km My App reading: 43.05 km Demo application reading: 43 km
Case 02 (02/12/2023): Only My app was activated, and the demo application was disabled.
Observations:
- My app sent new coordinates with intervals ranging from 4 to 10 minutes, even while the user was moving.
- most of the coordinates were missing.
Case 03 (04/12/2023): Only My app was activated, and the demo application was disabled.
Observations:
- My app sent new coordinates with intervals ranging from 4 to 10 minutes, even though the user was moving.
- 636 coordinates received out of 646, but most were the same or duplicate set of coordinates.
samples:0,
What do you think that does?
This is for getting no of samples ..sry i may be wrong but can you please look at my code and tell me what is missing in that ? How can i get it work?
What do you think "samples" means?
What do you think "samples" means?
It means no of samples location to fetch before returning best location
How many opportunities do you think the plug-in has to obtain a "best location" with 0 attempts?
With samples: 0, you're going to get the last known location every single time.
Got it . But initially i was using desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH, and persist: false, with that also i got duplicate coordinates.
I suggest you carefully read all the option for .getCurrentPosition.
desiredAccuracy for .getCurrentPosition doesn't mean what you think it does.
.getCurrentPosition always uses highest possible accuracy.
One should never use samples: 0. It basically has the same effect as samples: 1 (returns the last known location --always-- and never turns on location-services to fetch a fresh location.
One should never use samples: 0. It basically has the same effect as samples: 1 (returns the last known location --always-- and never turns on location-services to fetch a fresh location.
ok Thanks . I'll try with samples:4 or something
Should I use debug build to test this?
Yes, of course.
This plugin works fine but if the device is ideal for some time ex: 3-4 hours then it is sending duplicate coordinates evening moving . Do you have any solution for this?
Let me know how to reproduce it. I've never heard of this issue.
Are you watching the plug-in logs?
Let me know how to reproduce it. I've never heard of this issue.
Start tracking and keep your device ideal for 3-4 hours and then again start moving then you can see the duplicate coordinates
Ok, I've been doing that every day for years and I don't experience that. I often carry at least 2 Android test devices in backpack everywhere I go. Sometimes I carry 10 different Android devices.
I suggest you install the demo app linked in the readme. It's what I use.
- Nexus 4 @ 4.4.4
- Nexus 5 @ 6.0.1
- Motorola Moto G @ 6.0.0
- Google Pixel @ 10
- Google Pixel 3a @ 12
- Google Pixel 6 @ 14
- Samsung Galaxy S20 FE @ 13
- Samsung J @ 6.0.1
- Samsung A510 @ 8.0.0
- Huawei P20 Lite (ANE-LX3) @ 8.0.0
- Huawei Nova 9 SE (JLN-LX1) @ EMUI 12.0.1
- Huawei P40 Lite (JNY-LX1) @ EMUI ???
- Huawei P40 Pro (ELS N04) @ EMUI 11
- XIAOMI MI A2 Lite @ 10.0.0
- Nokia TA-1027 @ 8.0.0
- OnePlus A5010 @ 9.0.0
Are you watching the plug-in logs?
During testing my phone screen was off , which was the use case of mine . No i wasn't watching the plugin logs because i tested this in release version apk .
I suggest you analyze your logs.
I suggest you analyze your logs.
Ok
In this approach how can I track logs?
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.