React-native-background-geolocation: BakgroundGeolocation onLocation callback stops triggering after a few times.

Created on 25 Jan 2018  路  8Comments  路  Source: transistorsoft/react-native-background-geolocation

Your Environment

  • Plugin version: ^2.10.1
  • Platform: iOS or Android: Android
  • OS version: 8.1.0
  • Device manufacturer / model: Virtual Device
  • React Native version (react-native -v): 0.52.0
  • Plugin config

distanceFilter: 10,
locationUpdateInterval: 1000,
stopOnTerminate: true,
startOnBoot: false,
foregroundService: false,
debug: false,

Expected Behavior

The BackgroundGeolocation.on('location') should be triggered on each location change

Actual Behavior

The BackgroundGeolocation.on('location') stops being triggered after 4 or 5 changes.

Steps to Reproduce

  1. Install the plugin
  2. Configure it and set a callback for the BackgroundGeolocation.on('location')
  3. Run it on a Android Emulator
  4. Emulate the route via GPS Data Playback feature on Android Emulator extended controls (settings)

Context

I want to trigger an API call on each location change in order to track a user location but only the first changes are being triggered. Even the GPS Data Playback having a really huge path to follow. It only triggers the first 4 or 5 changes and then stops to trigger. If opening the Google Maps, I can see my position being tracked through the whole path when using the same GPS Data Playback.

Debug logs

https://pastebin.com/raw/K3JchhGG
Obs.: I've debugged as "[LOCSERVICE]" on each time a BackgroundGeolocation callback is triggered.

Most helpful comment

Hi @christocracy !

Thanks for your feedback. It helped solve my problem!

All 8 comments

If checking the log itself, you may see that the last LOCSERVICE log triggering a location was on 01-25 14:02:19.270.

The GPS Data Playback was still running at that time. And I've kept logging 2min later. With no more LOCSERVICES being triggered showing the next locations.

Although there is a...

TSLocationManager: [c.t.l.BackgroundGeolocationService onActivityRecognitionResult] still (100%)

... before stopping that it suggests it recognized the device as "still". The problem is that the GPS Data Playback was still running.

The plugin uses MotionActivity API (uses gyroscope/accelerometer/compass) to determine when to listen to locations.

If the MotionActivity API says the plugin is stationary, the plugin isn't listening to locations.

If you want to test in Simulator (or mock location app, such as Lockito), you must manually put the plugin into the moving state via BackgroundGeolocation.changePace(true);

@christocracy , thanks for your feedback!

imgur

I'm setting the changePace(true) after BackgroundGeolocation.start but stills the same behavior.

Is there a specific moment to activate the changePace?

Cheers!

Currently, even with changePace(true) he stills logs an activity change as

[LOCSERVICE] [activity change]{"confidence":100,"activity":"still"}

  1. The plugin persists state.enabled. Your if (!state.enabled) {} block isn't evaluating because state.enbled === true If you execute #start and reboot the app, state.enabled === true

  2. The activity comes from the motion-activity API (accelerometer,gyroscope,compass). If the device isn't moving, it will always be still.

BackgroundGeolocation.configure(config, (state) => {
  BackgroundGeolocation.changePace(true);
});

Hi @christocracy !

Thanks for your feedback. It helped solve my problem!

@christocracy Please let me know if I should create a new issue.

  1. Is it safe to say that I need to call changePace(true) just once after setConfig and not necessary in setInterval()?

    • If true, then in production application, can I still call changePace(true) _once_ to force geolocation updates?

  2. Is there any repercussion if I were to call start() without checking if state.enabled === true?

@iamjoyce Have you read the Philosophy of Operation?

The plugin strongly desires to be in the stationary state. When you execute changePace(true), the plugin enters the moving state. When the Motion API says the device is still, the plugin engages the stopTimeout timer.

When the stopTimeout timers expires, the plugin automatically switches back to stationary state (essentially executing changePace(false) upon itself).

No, you don't need setInterval.

Is there any repercussion if I were to call start()

No, the plugin will simply ignore your attempt to #start when already enabled. In the logs, you'll see:

鈿狅笍 Already started.  Ignored
Was this page helpful?
0 / 5 - 0 ratings