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

How do I initially (before reaching 200m) record positions accurately?

Open alfredvaa opened this issue 1 year ago • 1 comments

I am trying to use this plugin for a fitness tracking app. From what I have read in the docs it works as "expected", which is after the plugin has started I need to move a few hundred meters before I am starting to get positions. My use case is that the user presses a button in the app to start recording the path and I need positions of the first 200 meters as well.

I have seen that it is possible to force positions before the plugin starts to automatically getting positions, my question lies in what approach is the best one. Hopefully there is some configuration option to initially getting positions as well but I have not seen one, so I suspect not.

Is this plugin ment to be used for both background and foreground geolocation? Or am I supposed to use this in combination with expo-location for instance?

With only the BackgroundGeolocation.onLocation listener, and if I stand still, I get two location objects initially. And if I never move, I don't get any more locations. This means that I never get good accuracy either since the first location objects most often have bad accuracy. I get one object with sample: true and one object with event: motionchange.

Possible "solutions":

I can do something like this:

      BackgroundGeolocation.start().then(() => {
        setTimeout(() => {
          BackgroundGeolocation.getCurrentPosition({});
        }, 30000);
        setTimeout(() => {
          BackgroundGeolocation.getCurrentPosition({});
        }, 60000);
        setTimeout(() => {
          BackgroundGeolocation.getCurrentPosition({});
        }, 120000);
      });

which will trigger more onLocation executions and most often with better accuracy.

It is also possible to set

     heartbeatInterval: 1,
     preventSuspend: true,

in the configuration and then executing BackgroundGeolocation.getCurrentPosition({}); within the onHeartbeat listener, this will also trigger location events when standing still initially.

These solutions seems to be workarounds rather than great solutions so I wonder how I am supposed to do this? Or is it just not something that this plugin is ment to do?

For fitness tracking it is crucial to have position tracking active before starting to move, I get that this might not be as important in other use cases.

Your Environment

  • Plugin version: 4.16.5
  • Platform: iOS
  • OS version: 17.5
  • Device manufacturer / model: iPhone 15 pro
  • React Native version (react-native -v): 0.74.2
  • Plugin config
      desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_NAVIGATION,
      distanceFilter: 0,
      stopTimeout: 5,
      debug: false,
      logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
      stopOnTerminate: false,
      startOnBoot: true,
      disableElasticity: true,
      // heartbeatInterval: 1,
      // preventSuspend: true,

Expected Behavior

Getting positions initially without moving too much

Actual Behavior

User has to move a few hundred meters before it starts to receive locations.

Steps to Reproduce

Context

Getting better initial positions.

Debug logs

Logs
PASTE_YOUR_LOGS_HERE

alfredvaa avatar Aug 14 '24 16:08 alfredvaa

See API docs method .changePace

christocracy avatar Aug 14 '24 18:08 christocracy

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

github-actions[bot] avatar Sep 14 '24 01:09 github-actions[bot]

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

github-actions[bot] avatar Sep 28 '24 02:09 github-actions[bot]