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
655 stars 277 forks source link

plugin does not store location after app is terminated #697

Closed aaronharper123 closed 5 years ago

aaronharper123 commented 5 years ago

The plugin does not store location after the app is terminated. I am not using URL or params in the config object. Instead of this i am using this.bgGeo.getLocations() method to retrieve location but this method is not given location when the app is terminated but work fine in background and foreground.

Your Environment

My code: this.platform.ready().then(() => { this.bgGeo = (<any>window).BackgroundGeolocation; const subscription = this.batteryStatus.onChange().subscribe(status => { console.log(status.level, status.isPlugged); this.batteryLevel = status.level; }); this.onDeviceReady(); });

`onDeviceReady() {

const subscription = this.batteryStatus.onChange().subscribe(status => {
     console.log(status.level, status.isPlugged);
     this.batteryLevel = status.level;
  });

this.bgGeo.on('location', this.onLocation.bind(this));
this.bgGeo.on('motionchange', this.onMotionChange.bind(this));
this.bgGeo.on('activitychange', this.onActivityChange.bind(this));
this.bgGeo.on('geofence', this.onGeofence.bind(this));
this.bgGeo.on('http', this.onHttpSuccess.bind(this), this.onHttpFailure.bind(this));

// BackgroundGeoLocation is highly configurable.
this.bgGeo.ready({
    // Geolocation config
    desiredAccuracy: 0,
    distanceFilter: 100,
    stationaryRadius: 50,
    // Activity Recognition config
    stopTimeout: 5,
    // Application config
    debug: true,  // <-- Debug sounds & notifications.
    reset: true,
    logLevel: this.bgGeo.LOG_LEVEL_VERBOSE,
    stopOnTerminate: false,
    startOnBoot: true,
    method: "POST",
    autoSync: true,
    maxDaysToPersist: 3,

}, function(state) {
    // This callback is executed when the plugin is ready to use.
    console.log("BackgroundGeolocation ready: ", state);
     this.bgGeo.start();
});

}`

` onLocation(location, taskId) { console.log('- location: ', location); let toast = this.toastCtrl.create({ message: 'onLocation call', duration: 2000, position: 'bottom'}); toast.present(); if(location.sample === true) {

    this.bgGeo.getLocations().then((locations)=> {
      this.arrLocations = [];
      console.log("stored locations: ", locations);
      const subscription = this.batteryStatus.onChange().subscribe(status => {
               console.log(status.level, status.isPlugged);
               this.batteryLevel = status.level;
            });

            for(let i=0; i<locations.length; i++) {
                var millisec = new Date(locations[i].timestamp);
                var milliInDate = moment(millisec).format('YYYY-MM-DDTHH:mm:ss');

                this.arrLocations.push({
                    Lat: locations[i].coords.latitude,
                    Long: locations[i].coords.longitude,
                    Date: milliInDate,
                    BatteryPerc: this.batteryLevel
                });
            }

            setTimeout(()=> {
                 console.log('Background Location Data: '+JSON.stringify(this.arrLocations));
                 this.serverPush.pushPosition({
                     UserId: 4,
                     LocationData: this.arrLocations
                 });
             },3000);
    }).catch((err)=> {
      console.log('error: ', err);
    });

  }

this.bgGeo.finish(taskId);

}`

Actual Behavior

Steps to Reproduce

1. 2. 3. 4.

Context

Debug logs

aaronharper123 commented 5 years ago

after I get all stored location when the app is in background or foreground, I pushed to the server and after I delete the location, but when the app is closed then no any data are retrieved.

christocracy commented 5 years ago

The plugin automatically deletes its locations when your server returns HTTP 200.

christocracy commented 5 years ago

The plugin absolutely 100% persists every single location it records, regardless of background / foreground / after terminate.

christocracy commented 5 years ago

You realize that your Javascript code you're using to push locations to your server won't run on Android when the app is terminated?

This is why the plugin has its own HTTP service.

aaronharper123 commented 5 years ago

But i tested sir , i am not using any http param in config so how it returns 200 and how it can delete ?

christocracy commented 5 years ago

I test the plugin every day for the past three+ years. I have thousands of customers. You're doing something wrong. What do the logs say?

aaronharper123 commented 5 years ago

i create log for stored location and it goes null

christocracy commented 5 years ago

Stop banging your head against the wall and go play with my Sample App until you're more familiar with the plugin.

aaronharper123 commented 5 years ago

i am sure about code and you can also see in above

aaronharper123 commented 5 years ago

if am . i doing anything wrong then you can see above

christocracy commented 5 years ago

i am sure about code and you can also see in above

Sure like this

aaronharper123 commented 5 years ago

i tested again but same problem. this.bgGeo.getLocations() method gives mu empty array. If i am doing any wrong then please tell me

christocracy commented 5 years ago

XCode logs please.

aaronharper123 commented 5 years ago

╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 0 | df: -1.0m | age: 0.1s ╚═══════════════════════════════════════════════════════════ ✅-[TSLocationManager locationManager:didUpdateLocations:] Acquired motionchange position: <+37.42467819,-122.22918858> +/- 5.00m (speed 35.86 mps / course 311.13) @ 6/8/18, 8:11:06 PM India Standard Time ℹ️-[TSConfig persist] 🔵-[TSConfig incrementOdometer:] 174.9 🔵-[TSLocationManager startMonitoringStationaryRegion:radius:] Radius: 25 🔴-[TSLocationManager stopUpdatingLocation] 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 5.0 ✅-[TSLocationManager persistLocation:]_block_invoke INSERT: 1D87D562-82D3-4796-9715-C28EE424B3B8 2018-06-08 20:11:06.829981+0530 Galio[35114:378727] - location: [object Object] 2018-06-08 20:11:06.830310+0530 Galio[35114:378727] - motionchange: false [object Object] 2018-06-08 20:11:06.830498+0530 Galio[35114:378727] - location: [object Object] 2018-06-08 20:11:06.846485+0530 Galio[35114:378727] stored locations: [object Object] 2018-06-08 20:11:09.847298+0530 Galio[35114:378727] Background Location Data: [{"Lat":37.42467819,"Long":-122.22918858,"Date":"2018-06-08T20:11:06"}] 2018-06-08 20:11:09.875374+0530 Galio[35114:378727] {"_body":"","status":200,"ok":true,"statusText":"OK","headers":{"cache-control":["no-cache"],"content-length":["0"],"date":["Fri"," 08 Jun 2018 14:41:09 GMT"],"expires":["-1"],"pragma":["no-cache"],"server":["Microsoft-IIS/10.0"],"x-aspnet-version":["4.0.30319"],"x-powered-by":["ASP.NET"]},"type":2,"url":"http://property.zoomi.in:86/api/User/UserTracking"} ✅-[LocationDAO clear]_block_invoke Destroyed all locations 2018-06-08 20:11:09.879855+0530 Galio[35114:378727] - cleared database 🔵-[TSLocationManager onResume:] enabled? 1 ℹ️-[LocationDAO purge:] 3 2018-06-08 20:11:10.253608+0530 Galio[35114:378727] BackgroundMode: On simulator apps never pause in background! ℹ️-[TSDBLogger db_save] Log committed 🔵-[TSLocationManager locationManager:didExitRegion:] Exit stationary region 🔵-[TSLocationManager setPace:] 1 ℹ️-[TSConfig persist] 🎾-[SOMotionDetector startShakeDetection:] sample-rate: 0.2 | M7 DISABLED 🎾-[TSLocationManager startUpdatingLocation] Location-services: ON ℹ️+[LocationAuthorization run:] status: 3

📍<+37.42625701,-122.23121884> +/- 5.00m (speed 35.56 mps / course 316.05) @ 6/8/18, 8:11:11 PM India Standard Time

╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 1 | df: -1.0m | age: 0.0s ╚═══════════════════════════════════════════════════════════ ✅-[TSLocationManager locationManager:didUpdateLocations:] Acquired motionchange position: <+37.42625701,-122.23121884> +/- 5.00m (speed 35.56 mps / course 316.05) @ 6/8/18, 8:11:11 PM India Standard Time 🎾-[TSLocationManager startUpdatingLocation] Location-services: ON 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 5.0 ℹ️-[TSConfig persist] 🔵-[TSConfig incrementOdometer:] 425.9 ✅-[TSLocationManager persistLocation:]_block_invoke INSERT: 1337A8BA-EBA3-4242-9683-3953BD9B3165 ℹ️+[LocationAuthorization run:] status: 3 2018-06-08 20:11:11.671476+0530 Galio[35114:378727] - location: [object Object] 2018-06-08 20:11:11.671690+0530 Galio[35114:378727] - motionchange: true [object Object] 2018-06-08 20:11:11.672432+0530 Galio[35114:378727] - location: [object Object] 2018-06-08 20:11:11.708579+0530 Galio[35114:378727] stored locations: [object Object]

📍<+37.42648156,-122.23149125> +/- 5.00m (speed 35.28 mps / course 315.70) @ 6/8/18, 8:11:12 PM India Standard Time

╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 1 | df: 0.0m | age: 0.0s ╚═══════════════════════════════════════════════════════════ 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 5.0 ℹ️-[TSConfig persist] 🔵-[TSConfig incrementOdometer:] 460.6 ✅-[TSLocationManager persistLocation:]_block_invoke INSERT: BB856178-C2B9-41BC-81E2-CDBB8546CB1A 2018-06-08 20:11:12.612010+0530 Galio[35114:378727] - location: [object Object] 🔵-[TSLocationManager onSuspend:] enabled? 1) ℹ️-[TSDBLogger db_save] Log committed 2018-06-08 20:11:13.429357+0530 Galio[35114:378727] [Snapshotting] Snapshotting a view (0x7ffc230d3400, UIKeyboardImpl) that has not been rendered at least once requires afterScreenUpdates:YES.

📍<+37.42670804,-122.23176442> +/- 5.00m (speed 35.09 mps / course 315.70) @ 6/8/18, 8:11:13 PM India Standard Time

╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 1 | df: 0.0m | age: 0.0s ╚═══════════════════════════════════════════════════════════ 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 5.0 ℹ️-[TSConfig persist] 🔵-[TSConfig incrementOdometer:] 495.4 ✅-[TSLocationManager persistLocation:]_block_invoke INSERT: 6FFA2EC8-5C88-4B3A-9BC2-22CC4E982429 2018-06-08 20:11:13.598000+0530 Galio[35114:378727] - location: [object Object]

📍<+37.42693422,-122.23204530> +/- 5.00m (speed 35.02 mps / course 315.70) @ 6/8/18, 8:11:14 PM India Standard Time

╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 1 | df: 0.0m | age: 0.0s ╚═══════════════════════════════════════════════════════════ 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 5.0 ℹ️-[TSConfig persist] 🔵-[TSConfig incrementOdometer:] 530.8 ✅-[TSLocationManager persistLocation:]_block_invoke INSERT: 2DAB8DE6-6DD9-42A4-ACDC-F0DB642E4573 2018-06-08 20:11:14.601170+0530 Galio[35114:378727] - location: [object Object] ℹ️-[TSDBLogger db_save] Log committed 🔵-[TSLocationManager onAppTerminate] stopOnTerminate? 0 🔴-[SOMotionDetector stopShakeDetection] OFF 🔵-[TSLocationManager startMonitoringStationaryRegion:radius:] Radius: 28 🔴-[TSLocationManager stopUpdatingLocation] 2018-06-08 20:11:14.693788+0530 Galio[35114:378727] [TSBackgroundFetch onAppTerminate] 2018-06-08 20:11:14.694606+0530 Galio[35114:378727] [TSBackgroundFetch stop]

after i terminated the app in simulator , log goes to ended in xcode

aaronharper123 commented 5 years ago

at server side , if we can not put extra param then which object will push to server .

is this whole location object ?

screen shot 2018-06-08 at 8 21 04 pm

If whole object is pushed then i will manage at server side

christocracy commented 5 years ago

Location Data Schema

Custom locationTemplate

aaronharper123 commented 5 years ago

is battery.level gives current battery status ?

screen shot 2018-06-08 at 8 43 42 pm

christocracy commented 5 years ago

What do you think it would mean if I said to you in english "your battery level is 50%"?

aaronharper123 commented 5 years ago

i means it gives me in number ?

christocracy commented 5 years ago

i means it gives me in number ?

What do you think Float means?

aaronharper123 commented 5 years ago

hello sir sorry for that , i want to ask one, i want to post json object like:

{ "LocationData": { "Lat": "23.00002", "Long": "72.145452", "Date": "2018-04-30T12:53", "BatteryPerc": 44, "UserId": 4, } }

i am doing like this..

url: 'http://property.zoomi.in:86/api/User/UserTracking',
        httpRootProperty: 'LocationData',
        locationTemplate: '{"Lat":<%= latitude %>,"Long":<%= longitude %>, "Date":<%= timestamp %>, "BatteryPerc":<%= battery.level %>}',
        extras: {
          "UserId": 4
        }`

Is this OK or Not ?

christocracy commented 5 years ago

timestamp is a String. What do you think would happen if you had the JSON

{
  "Date": 2018-06-08T15:45:07.616Z
}

The plugin makes NO ASSUMPTIONS about quoting strings. You must quote your own strings.

..., "Date": "<%= timestamp %>", ...
aaronharper123 commented 5 years ago

Okkkk sir, thank you i will implement tomorrow and after that l will update you. till tomorrow , please don't close this issue

christocracy commented 5 years ago

Issues are for specific issues. They're not generalized support threads.