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

Getting duplicate coordinates while using getCurrentPosition method

Open SurajMohanty02 opened this issue 2 years ago • 22 comments

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

SurajMohanty02 avatar Dec 05 '23 05:12 SurajMohanty02

Are you observing the plug-in native logs?

See wiki "Debugging" and learn to observe the logs.

christocracy avatar Dec 05 '23 14:12 christocracy

samples:0,

What do you think that does?

christocracy avatar Dec 05 '23 14:12 christocracy

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:

  1. Both applications calculated distances based on the Odometer.
  2. My app fetched coordinates every 30 seconds without fail.
  3. 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:

  1. My app sent new coordinates with intervals ranging from 4 to 10 minutes, even while the user was moving.
  2. most of the coordinates were missing.

Case 03 (04/12/2023): Only My app was activated, and the demo application was disabled.

Observations:

  1. My app sent new coordinates with intervals ranging from 4 to 10 minutes, even though the user was moving.
  2. 636 coordinates received out of 646, but most were the same or duplicate set of coordinates.

SurajMohanty02 avatar Dec 05 '23 14:12 SurajMohanty02

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?

SurajMohanty02 avatar Dec 05 '23 14:12 SurajMohanty02

What do you think "samples" means?

christocracy avatar Dec 05 '23 14:12 christocracy

What do you think "samples" means?

It means no of samples location to fetch before returning best location

SurajMohanty02 avatar Dec 05 '23 14:12 SurajMohanty02

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.

christocracy avatar Dec 05 '23 15:12 christocracy

Got it . But initially i was using desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH, and persist: false, with that also i got duplicate coordinates.

SurajMohanty02 avatar Dec 05 '23 15:12 SurajMohanty02

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.

christocracy avatar Dec 05 '23 15:12 christocracy

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.

christocracy avatar Dec 05 '23 15:12 christocracy

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

SurajMohanty02 avatar Dec 05 '23 15:12 SurajMohanty02

Should I use debug build to test this?

SurajMohanty02 avatar Dec 05 '23 18:12 SurajMohanty02

Yes, of course.

christocracy avatar Dec 05 '23 18:12 christocracy

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?

SurajMohanty02 avatar Dec 20 '23 03:12 SurajMohanty02

Let me know how to reproduce it. I've never heard of this issue.

christocracy avatar Dec 20 '23 03:12 christocracy

Are you watching the plug-in logs?

christocracy avatar Dec 20 '23 03:12 christocracy

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

SurajMohanty02 avatar Dec 20 '23 05:12 SurajMohanty02

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

christocracy avatar Dec 20 '23 05:12 christocracy

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 .

SurajMohanty02 avatar Dec 20 '23 05:12 SurajMohanty02

I suggest you analyze your logs.

christocracy avatar Dec 20 '23 05:12 christocracy

I suggest you analyze your logs.

Ok

SurajMohanty02 avatar Dec 20 '23 05:12 SurajMohanty02

In this approach how can I track logs?

SurajMohanty02 avatar Dec 20 '23 06:12 SurajMohanty02

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Apr 19 '24 01:04 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar May 03 '24 01:05 github-actions[bot]