transistorsoft / cordova-background-geolocation-lt

The most sophisticated background location-tracking & geofencing module with battery-conscious motion-detection intelligence for iOS and Android.
http://www.transistorsoft.com/shop/products/cordova-background-geolocation
Other
656 stars 277 forks source link

Background location stops updating to firebase as well as own server after 10-12 min. #1368

Closed Nayank9 closed 18 hours ago

Nayank9 commented 1 year ago

Your Environment

this.zone.run(() => {
      // 1.  Listen to events.
      let timestamp;
      BackgroundGeolocation.onLocation(location => {
        //console.log('[location] - ', location);
        if (location.coords != undefined || location.coords != null) {
          timestamp = Date.now();
          //console.log('onLocation called....!');
          this.updateLocation(location.coords.latitude, location.coords.longitude);
        }
      });

      BackgroundGeolocation.onMotionChange(event => {
        //console.log('[motionchange] - ', event.isMoving, event.location);
        if (event.location.coords != undefined || event.location.coords != null) {
          timestamp = Date.now();
          //console.log('onMotionChange called....!');
          this.updateLocation(event.location.coords.latitude, event.location.coords.longitude);
        }
      });

      BackgroundGeolocation.onHttp(response => {
        //console.log('[http] - ', response.success, response.status, response.responseText);
      });

      BackgroundGeolocation.onProviderChange(event => {
        //console.log('[providerchange] - ', event.enabled, event.status, event.gps);
      });

      // 2.  Configure the plugin with #ready
      BackgroundGeolocation.ready({
        locationAuthorizationRequest: 'Always',
        backgroundPermissionRationale: {
          title: "Allow {applicationName} to access to this device's location in the background?",
          message: "In order to track your activity in the background, please enable {backgroundPermissionOptionLabel} location permission",
          positiveAction: "Change to {backgroundPermissionOptionLabel}",
          negativeAction: "Cancel"
        },
        reset: true,
        debug: false,
        // logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
        desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
        distanceFilter: 15,
        // url: 'http://my.server.com/locations',
        autoSync: true,
        stopOnTerminate: false,
        startOnBoot: true
      }, (state) => {
        //console.log('[ready] BackgroundGeolocation is ready to use');
        if (!state.enabled) {
          // 3.  Start tracking.
          BackgroundGeolocation.start();
        }
      });
    })
//Firebase call
let loc = {
        id: 0,
        userId: driverProfile.userId,
        uuid: driverProfile.uuid,
        latitude: '' + latitude,
        longitude: '' + longitude,
        latitudeDelta: '0.05',
        longitudeDelta: '0.02',
      };
      let newData = this.ref.child('DR-' + driverProfile.userId);
      newData.set({
        id: 0,
        userId: driverProfile.userId,
        uuid: this.userdata.uuid,
        latitude: '' + latitude,
        longitude: '' + longitude,
        // drivercode: this.driverProfile.envmode
      });

Expected Behavior

Actual Behavior

Steps to Reproduce

1. 2. 3. 4.

Context

Debug logs

Logs ``` PASTE_YOUR_LOGS_HERE ```
christocracy commented 1 year ago

See Wiki Debugging and learn to fetch logs from the plugin using the method .emailLog.

Nayank9 commented 1 year ago

@christocracy can you please share that plugin link if you have, I have searched for emailLog plugin but I didn't find anything.

christocracy commented 1 year ago

It’s a Method of this plugin.

search the api docs for “emailLog”.

you’re reading the api docs, right?

Nayank9 commented 1 year ago
Screenshot 2022-10-16 at 7 43 53 PM

@christocracy I have added emailLog method but I didn't receive any email, you can see in console log

christocracy commented 1 year ago

That’s between your device mail client and the receiving mail server.

Nayank9 commented 1 year ago

background-geolocation.log @christocracy can you please check attached log file

christocracy commented 1 year ago

Have you looked at this file yourself?

Nayank9 commented 1 year ago

@christocracy Yes I have checked but I didn’t get what's the wrong in it, can you please let me know what might be the issue in my code

christocracy commented 1 year ago

You've provided ~45 min worth of logs.

What is the timestamp within that 45min where you experienced your issue "Background location stops updating to firebase as well as own server after 10-12 min"?

Nayank9 commented 1 year ago

@christocracy When app goes to background probably after 10-12 min it stops executing following code let newData = this.ref.child('DRIV-' + this.driv_id; newData.set({ userId: this.driv_id, uuid: uuid, latitude: lat, longitude: long, heading: heading, time: time, online: onlineStatus, name: driverProfile.firstName, });

christocracy commented 1 year ago

Throughout the 45min of the logs you've posted, the plugin is in the stationary state.

You should not expect the plugin to record locations while in the stationary state.

Are you aware of this plugin's Philosophy of Operation, where it only turns on location-services to track location when the device is detected to be moving? When the device is stationary, the plugin has turned off location-services to conserve energy.

🔵 Acquired motionchange position, isMoving: false

Only when you go outside and move (eg: a 1km walk) should you expect the plugin to turn on location-services and record location.

Nayank9 commented 1 year ago

@christocracy I tested outside when app goes to background it stops sending location to firebase & when app opens it is sending cached location, as per my requirement location should update if app goes to background.

christocracy commented 1 year ago

tested outside when app goes to background it stops sending location to firebase

Now fetch your logs and tell me the exact timestamp range where your problem occurred.

Nayank9 commented 1 year ago

@christocracy as you requested, please check attached log file. background-geolocation_2010.log

christocracy commented 1 year ago

and tell me the exact timestamp range where your problem occurred

Nayank9 commented 1 year ago

@christocracy I think it works when device is moving but I have another requirement where app should send current location within 15 min time interval. I'm using heartbit interval but it's not working please check my following code BackgroundGeolocation.ready({ locationAuthorizationRequest: 'Always', backgroundPermissionRationale: { title: "Allow {applicationName} to access to this device's location in the background?", message:This app sends your location data to your employer whenever your job clock is activated, even when the app is closed or not in use., positiveAction: "Change to {backgroundPermissionOptionLabel}", negativeAction: "Cancel" }, reset: true, debug: true, logLevel: BackgroundGeolocation.LOG_LEVEL_INFO, desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH, distanceFilter: 15, // url: 'http://my.server.com/locations', heartbeatInterval: 60 * 15, preventSuspend: true, autoSync: true, stopOnTerminate: false, startOnBoot: true }, (state) => { //console.log('[ready] BackgroundGeolocation is ready to use'); if (!state.enabled) { // 3. Start tracking. BackgroundGeolocation.start(); } });

christocracy commented 1 year ago

I suggest you decrease your heartbeatInterval to a lower value to test.

Nayank9 commented 1 year ago

@christocracy okay I will check, also what is the use of BackgroundFetch configuration.

christocracy commented 1 year ago

what is the use of BackgroundFetch configuration.

Read its readme. It’s perfectly explained there.

github-actions[bot] commented 2 weeks ago

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

github-actions[bot] commented 18 hours ago

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