Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last update not working #102

Closed
mrsek opened this issue Apr 13, 2016 · 36 comments
Closed

Last update not working #102

mrsek opened this issue Apr 13, 2016 · 36 comments

Comments

@mrsek
Copy link

mrsek commented Apr 13, 2016

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
Copy link
Member

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
#102

Snet form Gmail Mobile

@christocracy
Copy link
Member

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
#102 (comment)

Snet form Gmail Mobile

@mrsek
Copy link
Author

mrsek commented Apr 13, 2016

   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
Copy link
Member

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
#102 (comment)

Snet form Gmail Mobile

@mrsek
Copy link
Author

mrsek commented Apr 13, 2016

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

@christocracy
Copy link
Member

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

<plugin name="cordova-background-geolocation-lt" spec="1.5.1" />

@christocracy
Copy link
Member

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

@mrsek
Copy link
Author

mrsek commented Apr 15, 2016

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
Copy link
Member

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
#102 (comment)

Snet form Gmail Mobile

@mrsek
Copy link
Author

mrsek commented Apr 15, 2016

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
Copy link
Member

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
#102 (comment)

Snet form Gmail Mobile

@mrsek
Copy link
Author

mrsek commented Apr 15, 2016

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

@christocracy
Copy link
Member

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
#102 (comment)

Snet form Gmail Mobile

@mrsek
Copy link
Author

mrsek commented Apr 17, 2016

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
Copy link
Member

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
Copy link

chandriano commented May 4, 2016

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

@mrsek
Copy link
Author

mrsek commented May 4, 2016

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
Copy link
Member

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

@mrsek
Copy link
Author

mrsek commented May 11, 2016

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
Copy link
Member

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.

`

MyApp

MyAppapplication

MyApp

`


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#102 (comment)

Snet form Gmail Mobile

@pdfowler
Copy link

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
Copy link
Member

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
#102 (comment)

Snet form Gmail Mobile

@mrsek
Copy link
Author

mrsek commented May 19, 2016

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

@pdfowler
Copy link

@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
Copy link
Member

@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
Copy link
Member

Status please.

@mrsek
Copy link
Author

mrsek commented Jun 4, 2016

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
Copy link
Member

christocracy commented Jun 4, 2016

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
Copy link
Member

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
Copy link
Author

mrsek commented Jun 4, 2016

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 👍

@christocracy
Copy link
Member

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
Copy link
Member

christocracy commented Jun 4, 2016

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

@mrsek
Copy link
Author

mrsek commented Jun 4, 2016

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
Copy link
Author

mrsek commented Jun 20, 2016

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
Copy link
Member

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
#102 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AAA6l2ItyDCjNSq1eoAxKuJBM5VQIT5yks5qNh5OgaJpZM4IGCwJ
.

Snet form Gmail Mobile

@mrsek
Copy link
Author

mrsek commented Jun 22, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants