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

Last update not working #102

Closed mrsek closed 7 years ago

mrsek commented 8 years ago

Hi, i use phonegap build version and i noticed that bgGeo.configure sucess callback, is call several times. If i delete app, this callback is call only once (first time), but if i close app and run again, than it is called several times.

Another problem is that success location callback is called only at start app. After that no location callback is made. I drove for 1 hour.

christocracy commented 8 years ago

Each platform is a completely different animal. You are not telling me which platform.

On Wednesday, April 13, 2016, mrsek notifications@github.com wrote:

Hi, i use phonegap build version and i noticed that bgGeo.configure sucess callback, is call several times. If i delete app, this callback is call only once (first time), but if i close app and run again, than it is called several times.

Another problem is that success location callback is called only at start app. After that no location callback is made. I drove for 1 hour.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/transistorsoft/cordova-background-geolocation-lt/issues/102

Snet form Gmail Mobile

christocracy commented 8 years ago

Show me your js

On Wednesday, April 13, 2016, mrsek notifications@github.com wrote:

I use ios platform.

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/transistorsoft/cordova-background-geolocation-lt/issues/102#issuecomment-209226886

Snet form Gmail Mobile

mrsek commented 8 years ago
   bgGeo = window.BackgroundGeolocation;

    var bgGeoCallback = function (location, taskId) {

        var Now = Date.now().addMinutes(-new Date().getTimezoneOffset()).toISOString();
        var TimeStamp = new Date().getTime();

        var obj = [];
        var positionObj = {
            "timestamp": location.timestamp,
            "coords": location.coords,
            "DateUTC": Now
        };

        obj.push(positionObj);

        $.ajax({
            url: localStorage.apiLink + "positions",
            headers: {
                "Content-Type": "application/json;charset=UTF-8",
                'X-iReza-Region': localStorage.region,
                'Authorization': "Bearer " + localStorage.userName
            },
            data: JSON.stringify(obj),
            type: "POST"
        });
        localStorage.lastKnownLocation = location.coords.latitude + "," + location.coords.longitude;

        bgGeo.finish(taskId);

        /*insertPositionToDB(positionObj, function (result) {                       
            bgGeo.finish(taskId);
        });
        */

    };

    // This callback will be executed if a location-error occurs.  Eg: this will be called if user disables location-services.
    var bgGeofailureFn = function (errorCode) {
        alert("Ne dela");
        console.warn('- BackgroundGeoLocation error: ', errorCode);
    }

    // Listen to location events & errors.
    bgGeo.on('location', bgGeoCallback, bgGeofailureFn);

    bgGeo.configure({            
        /*url: localStorage.apiLink + "PositionsPlugin",
        batchSync: false,
        maxBatchSize: 25,
        autoSync: true,
        headers: {
            "Content-Type": "application/json;charset=UTF-8",
            'X-iReza-Region': localStorage.region,
            'Authorization': "Bearer " + localStorage.userName
        },*/
        maxDaysToPersist: 1,
        //maxRecordsToPersist:300,
        desiredAccuracy: 0,
        stationaryRadius: 20,
        distanceFilter: 65,            
        disableElasticity: true,                
        useSignificantChangesOnly: false,
        pausesLocationUpdatesAutomatically: true,
        disableStopDetection:false,
        minimumActivityRecognitionConfidence: 2,   // 0-100%.  Minimum activity-confidence for a state-change             
        activityRecognitionInterval: 8000,
        stopDetectionDelay: 30,  // Wait x minutes to engage stop-detection system
        stopTimeout: 5,  // Wait x miutes to turn off location system after stop-detection
        activityType: 'OtherNavigation',
        debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
        stopOnTerminate: true, // <-- enable this to clear background location settings when the app terminates
        preventSuspend: false,
        heartbeatInterval:60
    }, function(state) {
        // This callback is executed when the plugin is ready to use.
        console.log('BackgroundGeolocation ready: ', state);

        if (!state.enabled) {                
            bgGeo.start();
            alert("Startal sem");
        }
    }); 
christocracy commented 8 years ago

How are you installing the plugin with PGB?

On Wednesday, April 13, 2016, mrsek notifications@github.com wrote:

bgGeo = window.BackgroundGeolocation;

var bgGeoCallback = function (location, taskId) {

    var Now = Date.now().addMinutes(-new Date().getTimezoneOffset()).toISOString();
    var TimeStamp = new Date().getTime();

    var obj = [];
    var positionObj = {
        "timestamp": location.timestamp,
        "coords": location.coords,
        "DateUTC": Now
    };

    obj.push(positionObj);

    $.ajax({
        url: localStorage.apiLink + "positions",
        headers: {
            "Content-Type": "application/json;charset=UTF-8",
            'X-iReza-Region': localStorage.region,
            'Authorization': "Bearer " + localStorage.userName
        },
        data: JSON.stringify(obj),
        type: "POST"
    });
    localStorage.lastKnownLocation = location.coords.latitude + "," + location.coords.longitude;

    bgGeo.finish(taskId);

    /*insertPositionToDB(positionObj, function (result) {
        bgGeo.finish(taskId);
    });
    */

};

// This callback will be executed if a location-error occurs.  Eg: this will be called if user disables location-services.
var bgGeofailureFn = function (errorCode) {
    alert("Ne dela");
    console.warn('- BackgroundGeoLocation error: ', errorCode);
}

// Listen to location events & errors.
bgGeo.on('location', bgGeoCallback, bgGeofailureFn);

bgGeo.configure({
    /*url: localStorage.apiLink + "PositionsPlugin",
    batchSync: false,
    maxBatchSize: 25,
    autoSync: true,
    headers: {
        "Content-Type": "application/json;charset=UTF-8",
        'X-iReza-Region': localStorage.region,
        'Authorization': "Bearer " + localStorage.userName
    },*/
    maxDaysToPersist: 1,
    //maxRecordsToPersist:300,
    desiredAccuracy: 0,
    stationaryRadius: 20,
    distanceFilter: 65,
    disableElasticity: true,
    useSignificantChangesOnly: false,
    pausesLocationUpdatesAutomatically: true,
    disableStopDetection:false,
    minimumActivityRecognitionConfidence: 2,   // 0-100%.  Minimum activity-confidence for a state-change
    activityRecognitionInterval: 8000,
    stopDetectionDelay: 30,  // Wait x minutes to engage stop-detection system
    stopTimeout: 5,  // Wait x miutes to turn off location system after stop-detection
    activityType: 'OtherNavigation',
    debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
    stopOnTerminate: true, // <-- enable this to clear background location settings when the app terminates
    preventSuspend: false,
    heartbeatInterval:60
}, function(state) {
    // This callback is executed when the plugin is ready to use.
    console.log('BackgroundGeolocation ready: ', state);

    if (!state.enabled) {
        bgGeo.start();
        alert("Startal sem");
    }
});

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/transistorsoft/cordova-background-geolocation-lt/issues/102#issuecomment-209227037

Snet form Gmail Mobile

mrsek commented 8 years ago

`<gap:plugin name="cordova-background-geolocation-lt" source="npm" />`

christocracy commented 8 years ago

It's not <gap:plugin />. It's just <plugin />.

<plugin name="cordova-background-geolocation-lt" spec="1.5.1" />
christocracy commented 8 years ago

I just did a build of the SampleApp on PGB. It works fine.

mrsek commented 8 years ago

Now it is better but tracking stops after stationary mode for a while. If i stops for 1 hour and then go further, plugin not start. App is in background mode.

If then tap on app, the sound and notification for new location rings (debug mode). I think that app is suspended for some reason. Do you have any idea what is going on? I build app with PGB with settings you write.

Thanks in advance, Matjaž

christocracy commented 8 years ago

If stopTimeout expires, plugin enters stationary mode and your app suspends until another "significant change" event occurs.

On Friday, April 15, 2016, mrsek notifications@github.com wrote:

Now it is better but tracking stops after stationary mode for a while. If i stops for 1 hour and then go further, plugin not start. App is in background mode.

If then tap on app, the sound and notification for new location rings (debug mode). I think that app is suspended for some reason. Do you have any idea what is going on? I build app with PGB with settings you write.

Thanks in advance, Matjaž

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/transistorsoft/cordova-background-geolocation-lt/issues/102#issuecomment-210602298

Snet form Gmail Mobile

mrsek commented 8 years ago

How long is to "significant change" accours? My problem is that i need to track my customer as accurate as possible. What settings do you suggest? PreventSuspend or very long stopTimeout?

christocracy commented 8 years ago

Try either

On Friday, April 15, 2016, mrsek notifications@github.com wrote:

How long is to "significant change" accours? My problem is that i need to track my customer as accurate as possible. What settings do you suggest? PreventSuspend or very long stopTimeout?

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/transistorsoft/cordova-background-geolocation-lt/issues/102#issuecomment-210604588

Snet form Gmail Mobile

mrsek commented 8 years ago

Ok i will. But i drove for 20 km and plugin not started tracing.I will report results

christocracy commented 8 years ago

Try preventSuspend.

On Friday, April 15, 2016, mrsek notifications@github.com wrote:

Ok i will. But i drove for 20 km and plugin not started tracing.I will report results

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/transistorsoft/cordova-background-geolocation-lt/issues/102#issuecomment-210610647

Snet form Gmail Mobile

mrsek commented 8 years ago

I try preventSuspend mode.

Result Yesterday i start app in the morning. Than wait for 3 hours and than go to the trip. App start tracking instantly after start. It tracks me, until i stop. Than i was stationary for 5 hours. After that, we went home and app never start tracking. We drove for 1,5 hour. Interesting is that app was never suspended, because if tap on app from background, no sound rings. Today app is still not suspended. Here are last 3 notifications. Maybe it could help :

14:57 Location MOVING 15:57 Acquired stationary location 15:00 Resume location updates

I try other functions in app and when i tap on some button app crash. So maybe is memory leak or something like that. Is it possible that memory leak is in plugin or only in app?

christocracy commented 8 years ago

Are you still having issues? There is no memory leak in plugin. I've tested in a pure native environment for hours and the memory response is completely flat.

chandriano commented 8 years ago

Yes, I still with this problem, I'll try to do an ionic state reset, clean my database and try again

mrsek commented 8 years ago

Yes, the problem persist. Maybe is the problem in other plugins i use. The problem is always after stop detection. Before that it works ok.

It doesn't matter if i drive for 10 minutes or 2 hours. After stop detection, plugin stop working. I will make simple app with just plugin included. Hope it will work

christocracy commented 8 years ago

Test with my SampleApp so we're guaranteed to be running the same code.

mrsek commented 8 years ago

Hi,

i try your application with attached config.xml. I use phonegab build. Result are pretty much the same. App stop tracking after stop detection for a while.

Sometimes it start tracking again, but usually not. Yesterday was interesting. I start in the morning and then app after 500 meters notify Stationary region exit, but app not start tracking. Sometimes i have to press button to "wake up phone", and than app start tracking. I use this phone just for testing tracking, so normally phone is sleeping. I dont know if this is important.

A lot of times when i open app, button ("play/pause" ) is green ("play"), that means that tracking is off. But i never press pause button. Something is force app to stop tracking.

<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns   = "http://www.w3.org/ns/widgets"
    xmlns:gap   = "http://phonegap.com/ns/1.0"    
    id          = "xxx.phonegap.myapp"
    versionCode = "1"
    version     = "2.0.0" >

  <name>MyApp</name>

  <description>MyAppapplication </description>
  <access origin="*" />
  <author href="http://www.myapp.com/" email="support@myapp.com">MyApp</author>

  <preference name="android-build-tool" value="gradle" />

  <plugin name="cordova-background-geolocation-lt" />
  <plugin name="cordova-plugin-console" />
  <plugin name="cordova-plugin-device" />
  <plugin name="cordova-plugin-splashscreen" />
  <plugin name="cordova-plugin-whitelist" />

</widget>
christocracy commented 8 years ago

Are you aware the plugin automatically toggles tracking off based upon the accelerometer after you stop moving (#stopTimeout)

On Wednesday, May 11, 2016, mrsek notifications@github.com wrote:

Hi,

i try your application with attached config.xml. I use phonegab build. Result are pretty much the same. App stop tracking after stop detection for a while.

Sometimes it start tracking again, but usually not. Yesterday was interesting. I start in the morning and then app after 500 meters notify Stationary region exit, but app not start tracking. Sometimes i have to press button to "wake up phone", and than app start tracking. I use this phone just for testing tracking, so normally phone is sleeping. I dont know if this is important.

A lot of times when i open app, button ("play/pause" ) is green ("play"), that means that tracking is off. But i never press pause button. Something is force app to stop tracking.

`<?xml version="1.0" encoding="UTF-8" ?>

MyApp

MyAppapplication

MyApp

`

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/transistorsoft/cordova-background-geolocation-lt/issues/102#issuecomment-218357425

Snet form Gmail Mobile

pdfowler commented 8 years ago

the plugin automatically toggles tracking off based upon the accelerometer after you stop moving (#stopTimeout)

@christocracy - is preventSuspend they way to stop this, or is there a 'best practice' to resume tracking after being stopped for a while?

What I'm seeing (in debug mode):

  1. In my app, tracking is engaged, works well in the background as long as I'm moving. My bgGeo.on('location', ...) code is executing and posting updates to my server
  2. I stop, tracking stops and I see Stop-detection engaged in my notifications, followed by various Location: STATIONARY MESSAGES
  3. I start moving again, see Exit stationary region and Aggressive monitoring engaged, followed by a handful of Location: MOVING notifications.
  4. My bgGeo.on('location', ...) handler never gets triggered after the stop, despite the plugin logging the changes.

I think my setup is pretty vanilla (mostly copied from the demo-app), but happy to share more details as necessary. My gut is that my problems are due to a misunderstanding of the setup/configuration, and not necessarily in the plugin itself - but hope to add more info to help diagnose/track down the issue we (users) are having ...

christocracy commented 8 years ago

I do not have this problem in the sample app. Are you monitoring web console for js errors? Are monitoring Xcode logs?

On Wednesday, May 18, 2016, Patrick Fowler notifications@github.com wrote:

the plugin automatically toggles tracking off based upon the accelerometer after you stop moving (#stopTimeout)

@christocracy https://github.com/christocracy - is preventSuspend they way to stop this, or is there a 'best practice' to resume tracking after being stopped for a while?

What I'm seeing (in debug mode):

  1. In my app, tracking is engaged, works well in the background as long as I'm moving. My bgGeo.on('location', ...) code is executing and posting updates to my server
  2. I stop, tracking stops and I see Stop-detection engaged in my notifications, followed by various Location: STATIONARY MESSAGES
  3. I start moving again, see Exit stationary region and Aggressive monitoring engaged, followed by a handful of Location: MOVING notifications.
  4. My bgGeo.on('location', ...) handler never gets triggered after the stop, despite the plugin logging the changes.

I think my setup is pretty vanilla (mostly copied from the demo-app), but happy to share more details as necessary. My gut is that my problems are due to a misunderstanding of the setup/configuration, and not necessarily in the plugin itself - but hope to add more info to help diagnose/track down the issue we (users) are having ...

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/transistorsoft/cordova-background-geolocation-lt/issues/102#issuecomment-220202593

Snet form Gmail Mobile

mrsek commented 8 years ago

@christocracy: Did you try build sample app with phonegap build?. Maybe this is the problem. Could you please try and report. Thanks, Matjaž

pdfowler commented 8 years ago

@christocracy: I can't say for sure about the web-console since my best-case repro has been walking around or driving. Likewise for Xcode logs sadly. I've simplified my code to use the simple http based location checkin to the server and things worked well this morning. I have a (possibly unrelated) crash that I'm looking into - but it seems like things are working well for me at the moment.

I'll update as more info comes into focus

christocracy commented 7 years ago

@mrsek what version of the plugin are you using? The method signature to #configure has changed: you're using the new signature (where the config {} is the 1st param and 2nd param is the configure success callback, but maybe you're using an old version of the plugin, where this new signature wasn't yet applied. That would totally explain your observed behaviour.

Update to the latest version of the plugin.

christocracy commented 7 years ago

Status please.

mrsek commented 7 years ago

Sorry for late answer. I already have right code. I tested all week with your app and last plugin with phonegap build.

Results are: app work quite ok. Sometimes it happens, when app is slipping for long period of time, that you need to drive longer than 500 meters to start tracking. It needs up to 5-10 kilometers. Interesting is that if i press main button, than app starts traking immediately. I also test if i shake phone more (not just leave on cars dashboard), tracking start faster. Otherwise i think that your last update significantly works better, but i thinks there is still somethink to improve. Especially sometimes late start tracking, which in my case is crucial. I will test more and report result.

christocracy commented 7 years ago

Interesting is that if i press main button, than app starts traking immediately

This is totally normal. When you engage the phone like this, iOS immediately asks "where am I?" and fetches the current location with GPS. After that iOS asks "Are there any Geofence listeners that need to be evaluated?".

It completely depends upon the network environment. As the user moves around, the device is constantly switching cell-towers. These cell-tower change-events also return the current location of the device (though with very poor accuracy, like 1km accuracy or more.

Think of geolocations not as single points but as circles of radius accuracy meters. Calculating a geofence exit requires the 2 circles not intersect. If you record a stationary-geofence of 25 meters but the accuracy of that position was 100m, the stationaryRadius is effectively 100m.

In the following image, imagine the purple circle is the stationary-geofence of radius accuracy meters. The red circle is the inaccurate current location returned to the OS from a cell-tower change-event. When iOS evaluates its geofence listeners while the app is suspended, it will not fire the geofence exit event since the two circles are still currently intersecting, even though that location is clearly beyond your configured stationaryRadius

I don't know about your network environment, but iOS is also receiving Wifi triangulation events in addition to cell-tower change-events. These Wifi events are more frequent and far more accurate than cell-tower locations. Are you in an environment with few available Wifi signals? Do you have Wifi turned off?

christocracy commented 7 years ago

I don't know about the nature of your app, but preventSuspend will certainly assist with exit-detection, since this mode prevents your app from sleeping, constantly monitoring the accelerometer for movement. When the slightest bit of movement is detected, the plugin becomes "curious", turning on location-services at full power and requests a series of location-samples, manually evaluating the current-location against the stationary-geofence. Exit-detection can take 10-50 meters in most cases.

However, this mode will have an impact on battery-life so should only be used in specialized applications, like fleet-tracking, where the user can be assumed to have the device plugged into power in a vehicle.

mrsek commented 7 years ago

That makes sense. If i start from home, works every time (wifi at home, ..). At work, which is a little more between hills, it needs more time to start tracking. Wifi is always turned on.

My case is, that users must be tracked as accurate as possible in real time. I will try preventSuspend. Previously when i use this option it stop working after 1 hour every time. I will try with sample app. I will report result.

Thanks for all :+1:

christocracy commented 7 years ago

It's important to realize that when the plugin is in stationary-mode (without preventSuspend: true, your app, and more important my code are completely asleep. My plugin is at the mercy of iOS to evaluate the stationary-geofence. There's nothing I can do to assist, aside from preventSuspend: true

christocracy commented 7 years ago

In my dense urban of environment, I have preventSuspend running for days. I rarely see it fail.

mrsek commented 7 years ago

Thanks you for the explanation. I think is good for all, that know how plugin works in details. You can close issue now. If I found something strange, I will report.

mrsek commented 7 years ago

Hi, i start using preventSuspend mode. Yesterday it stop working for some reason. I wonder what happens if the preventSuspend fail? Is any option to start tracking again?

christocracy commented 7 years ago

Personally, I've never had it fail, even after several weeks.

However, the mechanism relies upon being able to fetch a location every 200 seconds. If you're ever in a position where location is not possible, preventSuspend might time-out and be forced into suspend.

preventSuspend is fragile.

On Monday, June 20, 2016, mrsek notifications@github.com wrote:

Hi, i start using preventSuspend mode. Yesterday it stop working for some reason. I wonder what happens if the preventSuspend fail? Is any option to start tracking again?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/transistorsoft/cordova-background-geolocation-lt/issues/102#issuecomment-227050670, or mute the thread https://github.com/notifications/unsubscribe/AAA6l2ItyDCjNSq1eoAxKuJBM5VQIT5yks5qNh5OgaJpZM4IGCwJ .

Snet form Gmail Mobile

mrsek commented 7 years ago

Hi, is it possible to remove funkcionality or somehow change it, that ios suspend app if location is not found in 200 seconds?