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.56k stars 427 forks source link

the execution time of watchPosition and the expected non-conformance #1775

Closed Simoon-F closed 3 weeks ago

Simoon-F commented 10 months ago

Your Environment

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

  1. Open the app
  2. Click button to trigger watchPosition

Context

Debug logs

Logs ``` PASTE_YOUR_LOGS_HERE ```
christocracy commented 10 months ago

What are you using .watchPosition for?

Simoon-F commented 10 months ago

What are you using .watchPosition for?

Timing use . watchPosition to obtain the latitude and longitude of the current device.

christocracy commented 10 months ago

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.

Simoon-F commented 10 months ago

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.

christocracy commented 10 months ago

Why specifically are you using .watchPosition? I want people to avoid using this method.

Simoon-F commented 10 months ago

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.

christocracy commented 10 months ago

.watchPosition is not designed for long-term use in the background.

call .changePace(true) and implement your own timer to call .getCurrentPosition

Simoon-F commented 10 months ago

.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.

Crysp commented 7 months ago

@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.

christocracy commented 7 months ago

You are not providing any information (plug-in version, platform, device model, etc).

Crysp commented 7 months ago

Your Environment

Code

BackgroundGeolocation.watchPosition(
  location => {
    console.log(location);
  },
  errorCode => {
    console.error('watchPosition', errorCode);
  },
  {
    interval: 1000,
    desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
  },
);
christocracy commented 7 months ago

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.

IMG_1343

IMG_1341

IMG_1342

Crysp commented 7 months ago

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

christocracy commented 7 months ago

Did you see my stop-watch images above? They are perfect.

Crysp commented 7 months ago

Yes. Looks like side effects produce this bug. Because I run watchPosition in clear environment and it works perfectly

christocracy commented 7 months ago

What do you mean by "side-effects"?

I don't agree this is a bug.

What are you using .watchPosition for?

Crysp commented 7 months ago

"side effects" is my code.

I'm using it for foreground location updates to display user on map.

github-actions[bot] commented 1 month ago

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

github-actions[bot] commented 3 weeks ago

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