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

Enabling background location #104

Closed
paultanner opened this issue Apr 20, 2016 · 24 comments
Closed

Enabling background location #104

paultanner opened this issue Apr 20, 2016 · 24 comments

Comments

@paultanner
Copy link

paultanner commented Apr 20, 2016

I just loaded up my previously-tested cordova app into a new iPhone and got no background responses. I discovered a setting that had to be set as "always" for the plugin to do its work. I am wondering if there is a way to determine this setting before trying to use it, better still a way to force it to "always" (or "never").
Thx.

@christocracy
Copy link
Member

After first deleting the app from my Phone, I just did a fresh install of Sample App

2016-04-20 09:25:23.938 BG Geo[6562:2824338] ╔═════════════════════════════════════════════════
2016-04-20 09:25:23.938 BG Geo[6562:2824338] ║TSLocationManager ► Configure
2016-04-20 09:25:23.938 BG Geo[6562:2824338] ╠═════════════════════════════════════════════════
2016-04-20 09:25:23.939 BG Geo[6562:2824338] ╟─ {
    activityRecognitionInterval = 10000;
    activityType = OtherNavigation;
    autoSync = true;
    batchSync = false;
    debug = true;
    deferTime = 0;
    desiredAccuracy = 0;
    disableElasticity = false;
    distanceFilter = 20;
    fastestLocationUpdateInterval = 1000;
    forceReloadOnBoot = false;
    forceReloadOnGeofence = false;
    forceReloadOnHeartbeat = false;
    forceReloadOnLocationChange = false;
    forceReloadOnMotionChange = false;
    foregroundService = true;
    heartbeatInterval = 60;
    locationUpdateInterval = 5000;
    method = POST;
    params =     {
        device =         {
            available = 1;
            cordova = "4.1.1";
            isVirtual = 0;
            manufacturer = Apple;
            model = "iPhone8,1";
            platform = iOS;
            serial = unknown;
            uuid = "07F0A017-8269-4816-855F-2A99F1064700";
            version = "9.3.1";
        };
    };
    preventSuspend = false;
    startOnBoot = false;
    stationaryRadius = 20;
    stopDetectionDelay = 0;
    stopOnTerminate = true;
    stopTimeout = 1;
    triggerActivities = "in_vehicle, on_bicycle, running, walking, on_foot";
    url = "http://posttestserver.com/post.php?dir=ionic-cordova-background-geolocation";
    useSignificantChangesOnly = false;
}
2016-04-20 09:25:23.939 BG Geo[6562:2824338] ✓ Request location authorization: requestAlwaysAuthorization

I see no issue here.

@christocracy
Copy link
Member

The default for locationAuthorizationRequest is Always. It always has been. If you want Always authorization, you shouldn't even worry about setting it.

The only reason this is even configurable today is because someone actually requested the ability (issue #70) to be able to request WhenInUse authorization so he could display the "Blue Bar".

You do not have to specify this. The plugin strongly desires Always authorization.

@christocracy
Copy link
Member

If I were you, I would analyze my other 3rd party plugins and ask "Might any of these other plugins be requesting WhenInUse authorization?"

@paultanner
Copy link
Author

paultanner commented Apr 21, 2016

Sorry, I'm not sure if I framed my question right. The new iPhone had the setting WhenInUse. I did not get the popup that you show above. Changed it manually via settings then it worked. My question was about how to detect that (whatever the cause) and inform the user that locations will not be recorded.

@christocracy
Copy link
Member

Show me the plugins in your app:

$ cordova plugins

@paultanner
Copy link
Author

com.transistorsoft.cordova.background-geolocation 1.4.1 "BackgroundGeolocation"
cordova-plugin-bluetoothle 3.0.1 "Bluetooth LE"
cordova-plugin-device 1.1.0 "Device"
cordova-plugin-dialogs 1.2.0 "Notification"
cordova-plugin-geolocation 2.1.0 "Geolocation"
cordova-plugin-network-information 1.1.0 "Network Information"
cordova-plugin-whitelist 1.2.1 "Whitelist"
org.apache.cordova.console 0.2.3 "Console"

Thx.

@christocracy
Copy link
Member

As I suspected, you're using cordova-plugin-geolocation. This plugin is requesting WhileInUse authorization before my plugin gets a chance to request Always. Once one plugin has requested location permission, no other plugin gets to change it or request a different permission.

I suggest you get rid of cordova-plugin-geolocation and just use mine.

@paultanner
Copy link
Author

Thx for suggestion. I was using it to find out whether location was enabled before the app got properly started. It's a dependency. I guess I need to find a different way to do that.

@christocracy
Copy link
Member

My plugin has a #getCurrentPosition method

@paultanner
Copy link
Author

paultanner commented May 31, 2016

Thx for that and sorry for delay in replying. Had to fix iPhone.
Anyway, I removed the other plugin then tried waiting for the callback from configure() and then calling getCurrentPosition(). For some reason it is not doing the success callback from configure(). the log says:

╔═════════════════════════════════════════════════
2016-05-31 12:09:42.388 AirSome![551:179149] ║TSLocationManager ► Configure
2016-05-31 12:09:42.389 AirSome![551:179149] ╠═════════════════════════════════════════════════
2016-05-31 12:09:42.391 AirSome![551:179149] ╟─ {
    activityRecognitionInterval = 5000;
    activityType = Fitness;
    debug = 1;
    desiredAccuracy = 10;
    disableElasticity = 0;
    distanceFilter = 5;
    minimumActivityRecognitionConfidence = 80;
    startOnBoot = 0;
    stationaryRadius = 5;
    stopDetectionDelay = 2;
    stopOnTerminate = 0;
    stopTimeout = 10;
    useSignificantChangesOnly = 0;
}
2016-05-31 12:09:42.394 AirSome![551:179149] ✓ Request location authorization: requestAlwaysAuthorization
2016-05-31 12:09:42.420 AirSome![551:179101] ► didChangeAuthorizationStatus 3
2016-05-31 12:09:42.430 AirSome![551:179101] ► LocationManager didChangeAuthorizationStatus: 3
2016-05-31 12:09:42.461 AirSome![551:179101] ► LocationManager didChangeAuthorizationStatus: 3

After that the plugin is silent. Did not get the authorisation popup as above. I tried this with different location settings - same result.

Update: I also tried calling configure() and not waiting for it. In this case I got callbacks from getCurrentPosition(). However, after calling start() I did not get any callbacks even when moving 1/2 mile, although I did see the odd message mentioning "stationary".

Any further suggestion pls? Thx.

@christocracy
Copy link
Member

bgGeo.configure(config, function(state) {
  console.log('- current state: ', state.enabled);
  if (!state.enabled) {
    bgGeo.start();
  }
});

@paultanner
Copy link
Author

paultanner commented Jun 1, 2016

Thx @christocracy

I had been calling it wrongly and am now using the above. At first it crashed horribly so after a while I realised this was a build issue and nuked everything to start again. Now seems OK, subject to testing on the move.

In this use case I do not want to start tracking immediately so after getting the location (to make sure user has enabled it) I call stop() and then start() again when ready to track.

Update: it is not recording location in the background. Here's my code:

    options = {
      desiredAccuracy: 10, // high power high accuracy
      distanceFilter: 5,
      stationaryRadius: 5,
      locationUpdateInterval: 1000,
      fastestLocationUpdateInterval: 5000,
      autoSync: false, // prevent automatic http requests
      activityType: 'Fitness', //'OtherNavigation', //CLActivityType        
      activityRecognitionInterval: 5000,
      stopTimeout: 5, // Wait x minutes to turn off location system after stop-detection
      stopDetectionDelay: 2, // Wait x minutes to engage stop-detection system
      debug: true, // hear sounds
      stopOnTerminate: false, // for headless operation
      startOnBoot: false // ditto 
    };
    // use the background locn plugin
    bgGeo = window.BackgroundGeolocation;
    bgGeo.on('location', onLocSuccess, onLocError);
    console.log('calling bgGeo.configure');
    bgGeo.configure(
      options,
      function(state) {
        console.log('success callback from bgGeo.configure', state.enabled);
        if (!state.enabled) {
          _bleLog('not calling bgGeo.start');
          //bgGeo.start();   // this done later in a callback from getState()
        }
        console.log('calling bgGeo.getCurrentPosition');
        bgGeo.getCurrentPosition(
          function(position, taskId) { // success
            console.log('callback from bgGeo.getCurrentPosition');
            onLocSuccess(position, taskId);   // log location (to be sent with sensor data)
            _bleLog('calling bgGeo.stop');
            bgGeo.stop();
            func();
          },
          onLocError,
          options
        );
      }
    );

You will see that I have switched off autoSync. My onLocSuccess() is supposed to be called by the 'location' event and that logs the location.

In the log I see it calling me back just once after I call start(). I wonder if it is correctly sensing movement?

Versions: cordova 6.2; iOS 9.3.2

Note: there may be a documentation issue on https://github.com/transistorsoft/cordova-background-geolocation-lt/wiki/Background-Tasks as this shows a different calling pattern for configure(). Nevertheless, I am following your example above.

@christocracy
Copy link
Member

When you say "it's not recording location in background", are you moving? You're aware that when initially #started, the plugin enters "stationary mode" and your app goes to sleep until the device exits the stationary geofence? You need to move typically 3 blocks away from current position to exit the stationary geofence, when your app will awaken and plugin begin aggressively tracking.

@paultanner
Copy link
Author

Yes. I was aware of that which is why I did moving tests. Since this is a walking app 3 blocks is a lot. I have added a call to bgGeo.changePace() which causes tracking. At the moment this is producing some readings, many of which look wildly out (by as much as 1/2 mile). As above, stationaryRadius is set to 5. I will do some more moving tests.

I did test the iPhone using endomondo. No wild readings in that case but the app may be handling them somehow.

@christocracy
Copy link
Member

You're not going to get the most accurate results possible because you're using desiredAccuracy: 10, which using only Wifi & Cell triangulation (NO GPS).

GPS is used only with desiredAccuracy: 0. Endomondo is certainly using desiredAccuracy: 0.

stationaryRadius: 5 is pointless. The plugin enforces a minimum of 25 now. iOS doesn't respond for at least 200 meters anyway.

@paultanner
Copy link
Author

Thx for that. The good news is that there was only 1 wild point per session. desiredAccuracy: 0 seems to fix it. If not (after more moving tests) I can just look for changes beyond walking speed and ignore them.

@Microzone
Copy link

hello christocracy , i have a problem with startOnBoot. I set it to true on my options but it does not trigger the location after restarting my device

@christocracy
Copy link
Member

iOS requires a significant location change to re-awaken. After closing, it
won't re-awaken until you move 100-200 meters, typically. This is an iOS
constraint.

On Tuesday, July 19, 2016, microzonesolutions notifications@github.com
wrote:

hello christocracy , i have a problem with startOnBoot. I set it to true
on my options but it does not trigger the location after restarting my
device


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#104 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAA6l4Nc8cnZeKZCrLf1xY5qv1rCJLHDks5qXJO5gaJpZM4ILlOz
.

Snet form Gmail Mobile

@Microzone
Copy link

Hi christocracy

Okay thanks, problem fixed but i have one more problem which i believe it will fix all my problems. How can i view my SQL lite output ? i believe the plugin has build-in SQL lite, so i do get my locations and all, but i want to know where can i view my SQL lite output because i want to retrieve all the data saved on SQL lite and post it to my server .

@christocracy
Copy link
Member

Have you looked at the docs and glanced through every possible method
available? Do that now.

The plugin has its own native http layer. You don't need to do http with
Ajax. The plugin is far better at this task than you are with Ajax. Since
it owns the database, it can automatically handle http errors and retry
later.

On Wednesday, July 20, 2016, microzonesolutions notifications@github.com
wrote:

Hi christocracy

Okay thanks, problem fixed but i have one more problem which i believe it
will fix all my problems. How can i view my SQL lite output ? i believe the
plugin has build-in SQL lite, so i do get my locations and all, but i want
to know where can i view my SQL lite output because i want to retrieve all
the data saved on SQL lite and post it to my server .


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#104 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAA6l-x3qNf34I8ibkaoN-KcIMp4DiHWks5qXgFPgaJpZM4ILlOz
.

Snet form Gmail Mobile

@Microzone
Copy link

image

That's how i am doing my post to my server, is there anything wrong ? i read your README and i followed your steps

@christocracy
Copy link
Member

Are you a customer?

@Microzone
Copy link

Yes i am

@christocracy
Copy link
Member

Why then are posting issues at the Free repo and not the private Premium, customers-only repo?

This link will be 404 to you, since I see you're not a member of the private repo.
https://github.com/transistorsoft/cordova-background-geolocation

If you're a customer, whoever ordered the product can provide you access by visiting the Customer Dashboard:
http://www.transistorsoft.com/shop/customers

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

No branches or pull requests

3 participants