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

It works only at the first time. #749

Closed pyeonjaesik closed 5 years ago

pyeonjaesik commented 5 years ago

Your Environment

Context

It works only at the first time. ( bgeo.strart();) following is my code

  $('#bgeo_start_btn').click(function(){
  document.addEventListener("deviceready", onDeviceReady_lbb);
function onDeviceReady_lbb() {
    // Get a reference to the plugin.
    var bgGeo = window.BackgroundGeolocation;

    //This callback will be executed every time a geolocation is recorded in the background.
    var callbackFn = function(location) {
        var coords = location.coords;
        var lat    = coords.latitude;
        var lng    = coords.longitude;
        console.log('- Location: ', JSON.stringify(location));        
    };

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

    // Listen to location events & errors.
    bgGeo.on('location', callbackFn, failureFn);
    // Fired whenever state changes from moving->stationary or vice-versa.
    // Fired whenever an HTTP response is received from your server.
    bgGeo.on('motionchange', function(isMoving) {
      console.log('- onMotionChange: ', isMoving);
    });
    // Fired whenever a geofence transition occurs.
    bgGeo.on('geofence', function(geofence) {
      console.log('- onGeofence: ', geofence.identifier, geofence.location);
    });    
    bgGeo.on('http', function(response) {
      console.log('http success: ', response.responseText);
    }, function(response) {
      console.log('http failure: ', response.status);
    });

    // BackgroundGeoLocation is highly configurable.
    bgGeo.ready({
        // Geolocation config
        desiredAccuracy: 0,
        distanceFilter: 10,
        stationaryRadius: 25,
        // Activity Recognition config
        activityRecognitionInterval: 5000,
        stopTimeout: 5,
        // Application config
        debug: true,  // <-- Debug sounds & notifications.
        stopOnTerminate: false,
        startOnBoot: true,
        // HTTP / SQLite config
        url: url+'/sendlocal',
        method: "POST",
        autoSync: true,
        maxDaysToPersist: 3,
        headers: {  // <-- Optional HTTP headers
            "X-FOO": "bar"
        },
        params: {   // <-- Optional HTTP params
            _id:window.localStorage['_id'],
            li:window.localStorage['li']
        }
    }, function(state) {
        // This callback is executed when the plugin is ready to use.
        console.log("BackgroundGeolocation ready: ", state);
    });
    bgGeo.start();
}            
        });    
});    

Debug logs

christocracy commented 5 years ago

You must not execute any plugin method which requests the location until the callback to #ready fires. That's why the method is called "ready".

bgGeo.ready(config, function(state) {
  if (!state.enabled) {
    bgGeo.start();  // <-- YES
  }
});
bgGeo.start();  // <-- NO!  You must wait until #ready callback.

You were warned about this in the README.

pyeonjaesik commented 5 years ago

I changed my code,but It is not still working. following is my code

pyeonjaesik commented 5 years ago

still working only at the first time.

christocracy commented 5 years ago

still working only at the first time.

Define "working".

See Debugging wiki.

pyeonjaesik commented 5 years ago

When my device call the function -bgeo.start(), my device detects location and send the data to my server. but, after that my device can not send location to my server any more.

christocracy commented 5 years ago

Are you watching the logs? The plugin is telling you everything it's doing.

bgGeo.ready({
  reset: true,
  logLevel: bgGeo.LOG_LEVEL_VERBOSE,
  .
  .  your existing config
  .
});
$ adb logcat -s TSLocationManager

Read the Debugging wiki.

pyeonjaesik commented 5 years ago

After I call the function bgeo.start(); and shaking for a while at foreground and teriminate my app, my device can detect location and send the data to my server. BUT After I call bgeo.start() and terminate my app right away, my device can not detect location. follwing is my debug 08-16 00:36:03.952 7132 7132 D TSLocationManager: [c.t.l.a.BackgroundGeolocation c] 08-16 00:36:03.952 7132 7132 D TSLocationManager: ๐Ÿ”ด Cleared callbacks 08-16 00:36:03.971 7132 7132 D TSLocationManager: [c.t.l.a.BackgroundGeolocation isMainActivityActive] NO

No log is written any more...

christocracy commented 5 years ago

This is correct. See docs for stopOnTerminate

Android Unlike iOS, the Android plugin's tracking will not pause at all when user terminates the app. However, only the plugin's native background service continues to operate, "headless" (in this case, you should configure an #url in order for the background-service to continue uploading locations to your server).

When you terminate an Android app, your ENTIRE Javascript is terminated. Obviously if you're using Javascript event-listeners upon the plugin, those will no longer fire.

This is why the plugin has its own persistence and HTTP services -- so it can continue to post locations to your server after the Android app has been terminated.

pyeonjaesik commented 5 years ago

Sorry, I can't understand why you make me see the docs which is about stopOnTerminate. The thing I want to know is "why my device CAN NOT detect location after terminating app without shaking my device " AND "why my device CAN detect location after shaking for a while and termination"

christocracy commented 5 years ago

why you make me see the docs which is about stopOnTerminate.

Because you terminated your app.

BUT After I call bgeo.start() and terminate my app right away

why my device CAN NOT detect location after terminating app without shaking my device

Go for a walk

pyeonjaesik commented 5 years ago

It seems like my device can not detect location without "EnableHeadlessMode :true". But After shaking for a while at the first time, without "EnableHeadlessMode:true" my device can detect loction even in the background

christocracy commented 5 years ago

Forget about shaking and forget about enableHeadless. Go for a walk. Listen to the plugin beep.

pyeonjaesik commented 5 years ago

What do you mean? -- "Listen to the plugin beep"

christocracy commented 5 years ago

debug: true. The plugin will beep.

christocracy commented 5 years ago

Because the โ€œbeepโ€ means a location was recorded.

If a location was recorded, a location was posted to your url.

If a location is posted to your url, you have no problem.

pyeonjaesik commented 5 years ago

Sorry, It was 3 AM in my country, I felt sleepy and did fall a sleep. I already set debug true and checkecd whether my device can detect location and send the data to server or not. Sometimes (after 1.Removing my app 2.cordova platform rm android 3.Cordova platform add android 4.Cordova run android ->launch) my device can detect location but sometimes (after 1.Removing my app 2.cordova platform rm android 3.Cordova platform add android 4.Cordova run android ->launch) My device can not detect location. When my device can not detect location, I can get the following debug TSLocationManager: [c.t.l.a.BackgroundGeolocation c] 08-16 00:36:03.952 7132 7132 D TSLocationManager: ๐Ÿ”ด Cleared callbacks 08-16 00:36:03.971 7132 7132 D TSLocationManager: [c.t.l.a.BackgroundGeolocation isMainActivityActive] NO

christocracy commented 5 years ago

There is nothing unusual about those log messages.

Removing / re-adding platform has no effect on the behaviour of the plugin.

I doubt you have any issue at all until you show me a log file after traveling 1km.

pyeonjaesik commented 5 years ago

I did that ( removing and add platform) to change my configure such as changing activityRecognitionInterval from10000 to 5000. It is strange that when rauching the app and shaking for a while and terminating, my device can detect location. But without that behavior my device detect location only one time.

--- I doubt you have any issue at all until you show me a log file after traveling 1km. I set the distancefilter 10. Then It should detect every 10m not 1km,right?

christocracy commented 5 years ago

Stop asking questions and get out of the office. Go for a long fieldtest.

Fetch your logfile after.

christocracy commented 5 years ago

This is my SampleApp today after terminating the app.

pyeonjaesik commented 5 years ago

Sorry for asking too much questions. You are my only the one teacher. I tried several times walking around my house but I will try more times. After that I will send the log file to you.

christocracy commented 5 years ago

You donโ€™t test by walking around the office. You test by walking hundreds of meters.

pyeonjaesik commented 5 years ago

I got it. I will try it.

2018๋…„ 8์›” 16์ผ (๋ชฉ) ์˜ค์ „ 9:31, Chris Scott notifications@github.com๋‹˜์ด ์ž‘์„ฑ:

You donโ€™t test by walking around the office. You test by walking hundreds of meters.

โ€” You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/transistorsoft/cordova-background-geolocation-lt/issues/749#issuecomment-413382965, or mute the thread https://github.com/notifications/unsubscribe-auth/Ak95nxqtBvUBh-Xlgjsl2vugflW0G1Q2ks5uRL18gaJpZM4V-Ge8 .

pyeonjaesik commented 5 years ago

Thank you for your advise

2018๋…„ 8์›” 16์ผ (๋ชฉ) ์˜ค์ „ 9:33, ํŽธ์žฌ์‹ vuswotlr@gmail.com๋‹˜์ด ์ž‘์„ฑ:

I got it. I will try it.

2018๋…„ 8์›” 16์ผ (๋ชฉ) ์˜ค์ „ 9:31, Chris Scott notifications@github.com๋‹˜์ด ์ž‘์„ฑ:

You donโ€™t test by walking around the office. You test by walking hundreds of meters.

โ€” You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/transistorsoft/cordova-background-geolocation-lt/issues/749#issuecomment-413382965, or mute the thread https://github.com/notifications/unsubscribe-auth/Ak95nxqtBvUBh-Xlgjsl2vugflW0G1Q2ks5uRL18gaJpZM4V-Ge8 .

pyeonjaesik commented 5 years ago

I walked around hundreds of meter. When I set config like this {distancefilter : 10 activityRecognitionInterval :5000} It works well. I have some question. Would you give me advice?

  1. My device detects location and send the data to server right after I call the bgeo.start(). But it can not detect location any more for a while. After I worked hundreds of meter and turn on and off my app repeatedly, my app can detect location every 10m. Why this problem occur?

  2. When my device battery is lower than 15%, background location detecting does not work at all. How to enable my device to detect location even though lower than 15% battery?

  3. In Andorid, when I turn off the location service(gps) my device can not detect location. I want to notice user to turn on the location with kind message when user turn off the location service. How to alarm users when they turn off location service?

  4. When I set the config like this {distancefilter:100 stationaryRadius:50 activityRecognitionInterval:3000} My device should detect location every 100m, right? I walked hundreds of meters But My device can not detect location at all except first time when I call the bgeo.start(). ( my device does not ring at all --beep)