transistorsoft / react-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection
http://shop.transistorsoft.com/pages/react-native-background-geolocation
MIT License
2.62k stars 428 forks source link

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

Open alfredvaa opened 1 month ago

alfredvaa commented 1 month ago

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

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

1. 2. 3. 4.

Context

Getting better initial positions.

Debug logs

Logs ``` PASTE_YOUR_LOGS_HERE ```
christocracy commented 1 month ago

See API docs method .changePace

github-actions[bot] commented 2 days ago

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