Coder Social home page Coder Social logo

pmwisdom / cordova-background-geolocation-services Goto Github PK

View Code? Open in Web Editor NEW
134.0 134.0 98.0 132 KB

Background Geolocation For Android and iOS

License: Apache License 2.0

JavaScript 12.56% Java 59.20% Swift 28.13% Objective-C 0.11%
background-geolocation cordova

cordova-background-geolocation-services's People

Contributors

erikboesen avatar julienroubieu avatar kvofreelance avatar pmwisdom avatar rpocklin avatar siddiq avatar zerounodue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-background-geolocation-services's Issues

Receive Geolocation Updates More Often

Hi! I need to get the user's geolocation while the app is in the background at a rate faster than once every second. However, I can't get the plugin to do so in iOS and I cannot even receive updates faster than once every 9 seconds on Android (even if I manually lower the interval). Any suggestions? My code is below:
` // Run when the device is ready
document.addEventListener('deviceready', function () {

    // Android customization
    // To indicate that the app is executing tasks in background and being paused would disrupt the user.
    // The plug-in has to create a notification while in background - like a download progress bar.
    cordova.plugins.backgroundMode.setDefaults({
        title:  'Notification',
        text:   'Text'
    });

    var bgLocationServices = window.plugins.backgroundLocationServices;

    // Enable background mode
    cordova.plugins.backgroundMode.enable();

    // Called when background mode has been activated
    cordova.plugins.backgroundMode.onactivate = function() {

        bgLocationServices.configure({
            //Both
            desiredAccuracy: 1, // Desired Accuracy of the location updates (lower means more accurate but more battery consumption)
            distanceFilter: 1, // (Meters) How far you must move from the last point to trigger a location update
            debug: false, // <-- Enable to show visual indications when you receive a background location update
            interval: 1000, // (Milliseconds) Requested Interval in between location updates.
            useActivityDetection: true, // Uses Activitiy detection to shut off gps when you are still (Greatly enhances Battery Life)

            //Android Only
            notificationTitle: 'Victorise Geolocation', // customize the title of the notification
            notificationText: 'Tracking', //customize the text of the notification
            fastestInterval: 1000, // <-- (Milliseconds) Fastest interval your app / server can handle updates
        });

        //Register a callback for location updates, this is where location objects will be sent in the background
        bgLocationServices.registerForLocationUpdates(function(location) {
                // console.log("We got an BG Update" + JSON.stringify(location));
                currPosLatLng = new google.maps.LatLng({lat: location.latitude, lng: location.longitude});
                posMarker.setPosition(currPosLatLng);
            },
            function(err) {
                console.log("Error: Didnt get an update", err);
        });


        bgLocationServices.start();
        //$scope.millisecondsInterval = 1000;
    };

    cordova.plugins.backgroundMode.ondeactivate = function() {
        $scope.secondsAdder = 0.01;
        bgLocationServices.stop();

        //$scope.millisecondsInterval = 10;
    };

}, false);`

Can't get basics to work

Hi,
Thanks for this plugin, it sounds exactly what I need.
If I could only get it to work...
I'm new to cordova, so I suspect it's a beginners stupidity....

I have this index.html:

<!DOCTYPE html>
<html>
    <head>
        <title>Background Geolocation Test</title>
    </head>
    <body>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/background-geolocation-test.js"></script>
    </body>
</html>

And this js/background-geolocation-test.js:


document.addEventListener('deviceready', function () {
  //Make sure to get at least one GPS coordinate in the foreground before starting background services
  navigator.geolocation.getCurrentPosition(function() {
   alert("Succesfully retreived our GPS position, we can now start our background tracker.");
   bgLocation();
  }, function(error) {
   alert(error);
  });
}, false);


function bgLocation() {
  if (!window.plugins || !window.plugins.backgroundLocationServices) {
    alert('BackgroundLocationServices not available');
  }

  //Get plugin
  var bgLocationServices = window.plugins.backgroundLocationServices;

  //Congfigure Plugin
  bgLocationServices.configure({
       //Both
       desiredAccuracy: 200, // Desired Accuracy of the location updates (lower means more accurate but more battery consumption)
       distanceFilter: 10, // (Meters) How far you must move from the last point to trigger a location update
       debug: true, // <-- Enable to show visual indications when you receive a background location update
       interval: 7000, // (Milliseconds) Requested Interval in between location updates.
       useActivityDetection: true, // Uses Activitiy detection to shut off gps when you are still (Greatly enhances Battery Life)

       //Android Only
       notificationTitle: 'BG Plugin', // customize the title of the notification
       notificationText: 'Tracking', //customize the text of the notification
       fastestInterval: 3000 // <-- (Milliseconds) Fastest interval your app / server can handle updates
  });

  //Register a callback for location updates, this is where location objects will be sent in the background
  bgLocationServices.registerForLocationUpdates(function(location) {
       alert("We got an BG location update" + JSON.stringify(location));
  }, function(err) {
       alert("Error - did not get a location update: " + err);
  });

  //Register for Activity Updates

  //Uses the Detected Activies / CoreMotion API to send back an array of activities and their confidence levels
  //See here for more information:
  //https://developers.google.com/android/reference/com/google/android/gms/location/DetectedActivity
  bgLocationServices.registerForActivityUpdates(function(activities) {
       alert("We got an activity update");
  }, function(err) {
       alert("Error - " + err);
  });

  //Start the Background Tracker. When you enter the background tracking will start, and stop when you enter the foreground.
  bgLocationServices.start();

  //bgLocationServices.stop();
 };

I'm using cordova 6.3.0. When executing the cmd "cordova run browser", I'm getting these alerts:
"Error - did not get a location update: Missing Command Error"
"Error - Missing Command Error"

and this in the Chrome browser console:

cordova.js:989 Error: exec proxy not found for :: BackgroundLocationServices :: configure
cordova.js:989 Error: exec proxy not found for :: BackgroundLocationServices :: registerForLocationUpdates
cordova.js:989 Error: exec proxy not found for :: BackgroundLocationServices :: registerForActivityUpdates
cordova.js:989 Error: exec proxy not found for :: BackgroundLocationServices :: start

Any idea?
Thanks so much in advance for your help!

Android location updates only triggering once when app is suspended

I can't get android to send continuous location updates in the background.
It only fires once when the device is suspended.

This is the configuration i am running:

bgLocationServices.configure({
                 // Both
                 desiredAccuracy: 20000, // Desired Accuracy of the location updates (lower means more accurate but more battery consumption)
                 distanceFilter: 0.1, // (Meters) How far you must move from the last point to trigger a location update
                 debug: true, // <-- Enable to show visual indications when you receive a background location update
                 interval: 1000, // (Milliseconds) Requested Interval in between location updates.

                 // Android Only
                 fastestInterval: 500, // <-- (Milliseconds) Fastest interval your app / server can handle updates
                 useActivityDetection: false // Uses Activitiy detection to shut off gps when you are still (Greatly enhances Battery Life)
            });

Even when i am running it through startAggressiveTracking it doesnt work.
Any thoughts on this?

Error trying to add package --> meteor add mirrorcell:background-geolocation-plus

im trying to add your package using the command
--> meteor add mirrorcell:background-geolocation-plus

but got this error
=> Errors while adding packages:

While selecting package versions:
error: unknown package: isobuild:isopack-2
Required by: mirrorcell:background-geolocation-plus 1.1.4

unknown package: isobuild:compiler-plugin
Required by: ecmascript 0.1.3-plugins.1

can you assist me on this error.. Thanks and
can i know where can i see your meteor code instead of the cordova code..

Error in Success callbackId: BackgroundLocationServices618474789 : ReferenceError: activities is not defined

hi, im trying to use the plugin, the notification is created already but in console give me this errors when the app open:

[INFO:CONSOLE(312)] "Error in Success callbackId: BackgroundLocationServices618474789 : ReferenceError: activities is not defined", source: file:///android_asset/www/cordova.js (312)

[INFO:CONSOLE(314)] "Uncaught ReferenceError: activities is not defined", source: file:///android_asset/www/cordova.js (314)

thanks i really need this plugin of you

Hook for actity function

Hi @pmwisdom,

This plugin is awesome! Looks at graphs and so on, i like it a lot!!!

The activity tracking feature is very interessting. I think it would be a cool idea to provide a hook/callback for the function that determines the most probable activity and keep your current logic als default.

It would
first go inline with just providing the position as is and keep Secret Sauce to the programmer,
and second would uncover device hardware problems (sometimes phones are flaky with hardware stuff)

Build in TestFlight - App closes immediately after opening

I use cordova version: 6.3.1

Only iOS , android works normal.

Without making any call plugin code in the error happens . Just load the library plugin already happens the error.

It works perfectly on iOS Simulator 9.3 and running on the device, also 9.3.

Only when I make the file to start the production process, the error happens in TestFlight.

Whenever I build ios the cord , and open the project in Xcode , I am asked to convert the code to the new standard Swift.

If I say yes, build error. If I say do not build works and error in TestFlight .

I've read all repository issues have not found anything like it.

I tried to include , without success: <preference name="deployment-target" value="7.0" />

Device log:

Sep 13 06:25:47 iPhone-de-Ricardo-Pedrosa SpringBoard[54] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
Sep 13 06:25:47 iPhone-de-Ricardo-Pedrosa SpringBoard[54] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
Sep 13 06:25:47 iPhone-de-Ricardo-Pedrosa SpringBoard[54] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
Sep 13 06:25:47 iPhone-de-Ricardo-Pedrosa securityd[89] <Error>:  secTaskDiagnoseEntitlements MISSING keychain entitlements: no stored taskRef found
Sep 13 06:25:47 iPhone-de-Ricardo-Pedrosa securityd[89] <Error>:  secTaskDiagnoseEntitlements MISSING keychain entitlements: no stored taskRef found
Sep 13 06:25:47 iPhone-de-Ricardo-Pedrosa amfid[179] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
Sep 13 06:25:47 iPhone-de-Ricardo-Pedrosa kernel[0] <Notice>: xpcproxy[962] Container: /private/var/mobile/Containers/Data/Application/335409B2-A379-416F-824B-3F33B1EB5F39 (sandbox)
Sep 13 06:25:47 iPhone-de-Ricardo-Pedrosa com.apple.xpc.launchd[1] (UIKitApplication:com.brave.garupa[0xd966][962]) <Notice>: Service exited due to signal: Trace/BPT trap: 5
Sep 13 06:25:47 iPhone-de-Ricardo-Pedrosa assertiond[63] <Warning>: Unable to obtain a task name port right for pid 962: (os/kern) failure (5)
Sep 13 06:25:47 iPhone-de-Ricardo-Pedrosa SpringBoard[54] <Warning>: Unable to register for exec notifications: No such process
Sep 13 06:25:47 iPhone-de-Ricardo-Pedrosa SpringBoard[54] <Warning>: Unable to obtain a task name port right for pid 962: (os/kern) failure (5)
Sep 13 06:25:47 iPhone-de-Ricardo-Pedrosa SpringBoard[54] <Warning>: Unable to obtain a task name port right for <FBApplicationProcess: 0x130e62bb0; com.brave.garupa; pid: 962>
Sep 13 06:25:47 iPhone-de-Ricardo-Pedrosa SpringBoard[54] <Warning>: Application 'UIKitApplication:com.brave.garupa[0xd966]' crashed.
Sep 13 06:25:47 iPhone-de-Ricardo-Pedrosa SpringBoard[54] <Warning>: Application '(null)' exited for an unknown reason.
Sep 13 06:25:47 iPhone-de-Ricardo-Pedrosa ReportCrash[963] <Notice>: Formulating report for corpse[962] Garupa
Sep 13 06:25:47 iPhone-de-Ricardo-Pedrosa ReportCrash[963] <Warning>: Saved type '109(109_Garupa)' report (1 of max 25) at /var/mobile/Library/Logs/CrashReporter/Garupa-2016-09-13-062547.ips.beta

Browser usage?

Thank you for sharing your plugin!

It doesn't state in the documentation whether this falls back to browser location services in web contexts.

Is it necessary to maintain a separate implementation for browsers if you want your app to be device-agnostic?

Coordinates retrieved from plugin are not always accurate.

Hello,

thx for your plugin. I have a problem with cofiguration, track isn't smooth, is there some recommended configuration for running or driving? The location updates data are very inaccurate.

My current config is:

desiredAccuracy: 0,
distanceFilter: 0,
interval: 9000,
fastestInterval: 5000,
useActivityDetection: true

Thx for your answer.

Correct initialization

Hi There,
Thanks for this very usefull plugin!
I have a question about initialization, on instruction there is:

//Make sure to get at least one GPS coordinate in the foreground before starting background services
navigator.geolocation.getCurrentPosition(function() {
 console.log("Succesfully retreived our GPS position, we can now start our background tracker.");
}, function(error) {
 console.error(error);
});
....

So is correct to initialize the plugin with:
bgLocationServices.start();

On the first location success? Ie:
navigator.geolocation.getCurrentPosition(function() {
 //omitting initialization parameters...
 bgLocationServices.start();
}, function(error) {
 console.error(error);
});

Somethimes switching background foreground lead to a strange problem, the coordinates seems to "fix" to a point and then this point i recalled many times...

Thanks
Rob

Can't install using plugman

Hello there!

When I try to install this using plugman I get an error saying that there is no AndroidManifest.xml, you have any idea why is this happening?.

Thanks!

Background geolocation uses less accurate method(s), not GPS

Hello,

Still having great fun with this plugin. I was wondering whether anyone has similar experiences to the symptoms described below and what they've done to fix them.

On a test drive I noticed that on my Android (v 5), in background mode, the position updates came in sporadically and inaccurately, especially when driving in the country side.
The foreground updates came in every second and on average have an accuracy of 3..10 meters, both in the city and in the country.
In the country, background updates were irregular and far and few between (maybe once, twice per minute). The accuracy of the updates was never better than 45 meters and sometimes huge (1000 meters), even though I specified desiredAccuracy=50.
It was much better in the city, but even there the location updates did not appear to obey the parameter settings passed into the plugin.

Then I realised that in background mode, the plugin must not be using GPS. It's probably using Wifi etc, which explains the differences seen between country and city behaviour. At first I thought the absence of GPS might be due to "battery saving mode", but it happens both with nearly full and nearly empty batteries and regardless of whether the phone is plugged into a charger (cigarette lighter) or not.

Everything changed for the better when I installed this plugin: https://play.google.com/store/apps/details?id=com.webmajstr.gpson&hl=e

Now, using this plugin, my background position updates on Android have the same accuracy as the foreground position updates (3..10 m) and the update frequency appears to obey the settings I gave it (interval=4000 ms in my case).

So with the above GPS Keeper app I now have a workaround in place. And I'm pretty happy.

But am still wondering -- is this how it is meant to work?
Have I misconfigured the plugin?
Is it the version of Android?
I haven't built to iOS yet, so cannot offer any info on that front.

keep updating when app is foreground

Hi, awesome job with this plugin! Is there any way that I can keep tracking even if the app is not in the background? I think it only works when the app goes to the background, but I need to keep tracking when the app is active.

Thanks

How to remove notification title and text on Android?

Hi, thanks for the plugin.
I wold like to remove the notification text and title, could you please let me know how to do it?
Also I keep on getting user activity status like start recording and stop recording when the app is running in the background, how to stop it?

Regards,
Chidan

What is the maximum interval that can be given ??

Great plugin @pmwisdom ..
Working good..
Can you please specify what is the maximum interval that can be given..
I need to update location only on hourly interval, even if the app is in background..
So can we give the interval / fastestInterval as 3600000 ms ?
Will it work..?

Launch failed with Release scheme

Thank you for useful plugin!

However, I got issue on iOS using it with release scheme.
App on beta-check for TestFlight was rejected twice using this plugin.

Error log:

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000120051088
Triggered by Thread:  0

Filtered syslog:
None found

Dyld Error Message:
Dyld Message: Library not loaded: @rpath/libswiftCore.dylib
  Referenced from: /var/containers/Bundle/Application/AB5B444F-2EB9-481C-8F65-2B410A06532D/Wingr.app/Wingr
  Reason: image not found
  Dyld Version: 390.7

Please, share any ideas what the reason of crash.
2016-06-10 15 20 43

Failed to install 'org.flybuy.cordova.background-location-services': Error: ENOENT: no such file or directory, open '/Users/platforms/ios/moving/Plugins/Bridging-Header.h'

While i CLI install this plugin with ionic plugin add https://.......git i get below error on ionic cli

Using this version of Cordova with older version of cordova-ios is being deprecated. Consider upgrading to [email protected] or newer.
The module "ConfigParser" has been factored into "cordova-common". Consider update your plugin hooks.
Creating new Bridging-Header.h at path: /Users/platforms/ios/moving/Plugins/Bridging-Header.h
Failed to install 'org.flybuy.cordova.background-location-services':Error: ENOENT: no such file or directory, open '/Users/platforms/ios/moving/Plugins/Bridging-Header.h'
at Error (native)
at Object.fs.openSync (fs.js:549:18)
at Object.fs.writeFileSync (fs.js:1156:15)
at createBridgingHeader (/Users/plugins/org.flybuy.cordova.background-location-services/hooks/add_swift_support.js:109:12)
at run (/Users/plugins/org.flybuy.cordova.background-location-services/hooks/add_swift_support.js:45:34)
at module.exports (/Users/plugins/org.flybuy.cordova.background-location-services/hooks/add_swift_support.js:11:5)
at runScriptViaModuleLoader (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:187:18)
at runScript (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:165:16)
at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:133:20
at _fulfilled (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:787:54)
Error: ENOENT: no such file or directory, open '/Users/platforms/ios/moving/Plugins/Bridging-Header.h'

iOS build fails on build.phonegap.com

Not sure if this is the correct place to post, but I'm trying to build an app with this plugin using build.phonegap.com and it's working great on android but I'm getting the following error for iOS.

** BUILD FAILED **

The following build commands failed:
    CompileSwift normal arm64 /project/ProjectPulse/Plugins/org.flybuy.cordova.background-location-services/CDVBackgroundLocationServices.swift
    CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(2 failures)

With a bunch of "undeclared type" errors like the below

/project/MyProject/Plugins/org.flybuy.cordova.background-location-services/CDVBackgroundLocationServices.swift:20:29: error: use of undeclared type 'UIWebView'
var LocationServiceWebView: UIWebView?

Relevant lines in config.xml (I think)

<preference name="deployment-target" value="7.0" />
<plugin name="cordova-background-location-services" spec="~1.0.0" />

From what I can gather from some googling this seems to be related to bridging headers but I have no experience with Swift so am not sure how to go about fixing it. Any help would be greatly appreciated. If this isn't the correct place to ask about this would it be possible to point me in the right direction?

Can't install plugin

W:\Temp\walker>cordova plugin add ./cordova-background-geolocation-services-master
Installing "org.flybuy.cordova.background-location-services" for android
WARNING: org.apache.cordova.geolocation has been renamed to cordova-plugin-geolocation. You may not be getting the latest version! We suggest you cordova plug in rm org.apache.cordova.geolocation and cordova plugin add cordova-plugin-geolocation.
Fetching plugin "org.apache.cordova.geolocation" via cordova plugins registry
npm http GET http://cordova.iriscouch.com/registry/_design/app/_rewrite/org.apache.cordova.geolocation/-/org.apache.cordova.geolocation-0.3.12.tgz
npm ERR! fetch failed http://cordova.iriscouch.com/registry/_design/app/_rewrite/org.apache.cordova.geolocation/-/org.apache.cordova.geolocation-0.3.12.tgz
npm http GET http://cordova.iriscouch.com/registry/_design/app/_rewrite/org.apache.cordova.geolocation/-/org.apache.cordova.geolocation-0.3.12.tgz
npm ERR! fetch failed http://cordova.iriscouch.com/registry/_design/app/_rewrite/org.apache.cordova.geolocation/-/org.apache.cordova.geolocation-0.3.12.tgz
npm http GET http://cordova.iriscouch.com/registry/_design/app/_rewrite/org.apache.cordova.geolocation/-/org.apache.cordova.geolocation-0.3.12.tgz
npm ERR! fetch failed http://cordova.iriscouch.com/registry/_design/app/_rewrite/org.apache.cordova.geolocation/-/org.apache.cordova.geolocation-0.3.12.tgz
Fetching from cordova plugins registry failed: getaddrinfo EAI_AGAIN cordova.iriscouch.com:80
Fetching plugin "org.apache.cordova.geolocation" via npm
npm http GET https://registry.npmjs.org/org.apache.cordova.geolocation
npm http 404 https://registry.npmjs.org/org.apache.cordova.geolocation
TypeError: Cannot read property 'latest' of undefined
at next (C:\Users\admin\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\npm\lib\cache.js:687:35)
at C:\Users\admin\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\npm\lib\cache.js:675:5
at saved (C:\Users\admin\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\npm\node_modules\npm-registry-client\lib\get.js:142
:7)
at C:\Users\admin\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\npm\node_modules\graceful-fs\polyfills.js:133:7
at FSReqWrap.oncomplete (fs.js:82:15)

plugin stopped working in iOS

Plugin stopped working in iOS. Im getting "Syntax error: Unexpected identifier 'exec'" at line 2 in BackgorundLocationServices.js

Derive from that error (I guess) I get " Error org.flybuy.cordova.background-location-services.BackgroundLocationServices does not exist"

I'm about to use the plugin in a production app, I would appreciate it a lot if you could look in to the problem.

Build errors in Xcode 8 Beta

I came across this while attempting to test my app on iOS 10 Beta. Seems that Xcode 8 is intolerant of deprecated Swift syntax, so throws lots of build errors for the current swift implementation of this plugin:

os x yosemite-2016-07-16-09-21-05

I have created a fork (https://github.com/dpa99c/cordova-background-geolocation-services) in which I've updated the syntax for Swift 3. This now builds OK in Xcode 8 Beta and runs fine on iOS 10 Beta.

I haven't created a pull request because I suspect that Swift 3 syntax is not supported by Xcode 7, but I can't test this since I had to remove Xcode 7 to make space for Xcode 8 Beta :-(

Full list of issues:

CDVBackgroundLocationServices.swift:169:12: Unnecessary check for 'iOS'; minimum deployment target ensures guard will always be true
CDVBackgroundLocationServices.swift:499:12: Unnecessary check for 'iOS'; minimum deployment target ensures guard will always be true
CDVBackgroundLocationServices.swift:563:12: Unnecessary check for 'iOS'; minimum deployment target ensures guard will always be true
CDVBackgroundLocationServices.swift:30:35: 'AutomotiveNavigation' has been renamed to 'automotiveNavigation'
CDVBackgroundLocationServices.swift:627:22: 'NSTimer' has been renamed to 'Timer'
CDVBackgroundLocationServices.swift:628:20: 'NSTimer' has been renamed to 'Timer'
CDVBackgroundLocationServices.swift:629:22: 'NSTimer' has been renamed to 'Timer'
CDVBackgroundLocationServices.swift:630:17: 'NSTimeInterval' has been renamed to 'TimeInterval'
CDVBackgroundLocationServices.swift:636:20: 'DISPATCH_QUEUE_PRIORITY_HIGH' has been renamed to 'DispatchQueue.GlobalAttributes.qosUserInitiated'
CDVBackgroundLocationServices.swift:405:10: Instance method 'locationManager(manager:didUpdateLocations:)' nearly matches optional requirement 'locationManager(_:didUpdateLocations:)' of protocol 'CLLocationManagerDelegate'
CDVBackgroundLocationServices.swift:467:10: Instance method 'locationManagerDidPauseLocationUpdates(manager:)' nearly matches optional requirement 'locationManagerDidPauseLocationUpdates' of protocol 'CLLocationManagerDelegate'
CDVBackgroundLocationServices.swift:471:10: Instance method 'locationManagerDidResumeLocationUpdates(manager:)' nearly matches optional requirement 'locationManagerDidResumeLocationUpdates' of protocol 'CLLocationManagerDelegate'
CDVBackgroundLocationServices.swift:475:10: Instance method 'locationManager(manager:didFailWithError:)' nearly matches optional requirement 'locationManager(_:didFailWithError:)' of protocol 'CLLocationManagerDelegate'
CDVBackgroundLocationServices.swift:489:10: Instance method 'locationManager(manager:didFinishDeferredUpdatesWithError:)' nearly matches optional requirement 'locationManager(_:didFinishDeferredUpdatesWithError:)' of protocol 'CLLocationManagerDelegate'
CDVBackgroundLocationServices.swift:59:9: 'NSNotificationCenter' has been renamed to 'NotificationCenter'
CDVBackgroundLocationServices.swift:65:9: 'NSNotificationCenter' has been renamed to 'NotificationCenter'
CDVBackgroundLocationServices.swift:71:9: 'NSNotificationCenter' has been renamed to 'NotificationCenter'
CDVBackgroundLocationServices.swift:92:34: 'argumentAtIndex' has been renamed to 'argument(at:)'
CDVBackgroundLocationServices.swift:93:50: Missing argument label 'distance:' in call
CDVBackgroundLocationServices.swift:94:37: 'argumentAtIndex' has been renamed to 'argument(at:)'
CDVBackgroundLocationServices.swift:95:47: 'argumentAtIndex' has been renamed to 'argument(at:)'
CDVBackgroundLocationServices.swift:96:44: Missing argument label 'type:' in call
CDVBackgroundLocationServices.swift:97:25: 'argumentAtIndex' has been renamed to 'argument(at:)'
CDVBackgroundLocationServices.swift:98:40: 'argumentAtIndex' has been renamed to 'argument(at:)'
CDVBackgroundLocationServices.swift:100:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:101:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:102:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:103:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:104:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:105:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:106:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:109:26: 'sendPluginResult(_:callbackId:)' has been renamed to 'send(_:callbackId:)'
CDVBackgroundLocationServices.swift:113:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:119:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:126:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:129:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:132:43: Missing argument label 'force:' in call
CDVBackgroundLocationServices.swift:137:26: 'sendPluginResult(_:callbackId:)' has been renamed to 'send(_:callbackId:)'
CDVBackgroundLocationServices.swift:141:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:148:26: 'sendPluginResult(_:callbackId:)' has been renamed to 'send(_:callbackId:)'
CDVBackgroundLocationServices.swift:152:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:154:28: 'init(status:messageAsString:)' has been renamed to 'init(status:messageAs:)'
CDVBackgroundLocationServices.swift:155:26: 'sendPluginResult(_:callbackId:)' has been renamed to 'send(_:callbackId:)'
CDVBackgroundLocationServices.swift:159:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:162:28: 'init(status:messageAsString:)' has been renamed to 'init(status:messageAs:)'
CDVBackgroundLocationServices.swift:163:26: 'sendPluginResult(_:callbackId:)' has been renamed to 'send(_:callbackId:)'
CDVBackgroundLocationServices.swift:168:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:170:80: Argument labels '(forTypes:, categories:)' do not match any available overloads
CDVBackgroundLocationServices.swift:176:27: 'sharedApplication()' has been renamed to 'shared()'
CDVBackgroundLocationServices.swift:176:47: 'registerForRemoteNotificationTypes' has been renamed to 'registerForRemoteNotifications(matching:)'
CDVBackgroundLocationServices.swift:176:108: 'Alert' has been renamed to 'alert'
CDVBackgroundLocationServices.swift:176:140: 'Sound' has been renamed to 'sound'
CDVBackgroundLocationServices.swift:176:172: 'Badge' has been renamed to 'badge'
CDVBackgroundLocationServices.swift:182:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:191:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:195:43: Missing argument label 'force:' in call
CDVBackgroundLocationServices.swift:201:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:205:43: Missing argument label 'force:' in call
CDVBackgroundLocationServices.swift:238:35: 'AutomotiveNavigation' has been renamed to 'automotiveNavigation'
CDVBackgroundLocationServices.swift:240:35: 'OtherNavigation' has been renamed to 'otherNavigation'
CDVBackgroundLocationServices.swift:242:35: 'Fitness' has been renamed to 'fitness'
CDVBackgroundLocationServices.swift:244:35: 'AutomotiveNavigation' has been renamed to 'automotiveNavigation'
CDVBackgroundLocationServices.swift:263:13: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:303:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:310:13: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:322:68: 'NSComparisonResult' has been renamed to 'ComparisonResult'
CDVBackgroundLocationServices.swift:328:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:331:36: Incorrect argument label in call (have 'keepCapacity:', expected 'keepingCapacity:')
CDVBackgroundLocationServices.swift:343:13: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:344:48: Missing argument label 'text:' in call
CDVBackgroundLocationServices.swift:349:47: Missing argument label 'loc:' in call
CDVBackgroundLocationServices.swift:352:25: 'setKeepCallbackAsBool' has been renamed to 'setKeepCallbackAs(_:)'
CDVBackgroundLocationServices.swift:353:42: 'sendPluginResult(_:callbackId:)' has been renamed to 'send(_:callbackId:)'
CDVBackgroundLocationServices.swift:346:38: 'runInBackground' has been renamed to 'run(inBackground:)'
CDVBackgroundLocationServices.swift:359:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:384:25: Result of call to 'beginNewBackgroundTask()' is unused
CDVBackgroundLocationServices.swift:386:13: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:388:13: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:393:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:427:21: Result of call to 'beginNewBackgroundTask()' is unused
CDVBackgroundLocationServices.swift:440:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:452:28: Missing argument label 'force:' in call
CDVBackgroundLocationServices.swift:456:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:458:28: Missing argument label 'force:' in call
CDVBackgroundLocationServices.swift:468:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:472:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:476:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:482:22: 'init(status:messageAsString:)' has been renamed to 'init(status:messageAs:)'
CDVBackgroundLocationServices.swift:483:21: 'setKeepCallbackAsBool' has been renamed to 'setKeepCallbackAs(_:)'
CDVBackgroundLocationServices.swift:484:38: 'sendPluginResult(_:callbackId:)' has been renamed to 'send(_:callbackId:)'
CDVBackgroundLocationServices.swift:478:34: 'runInBackground' has been renamed to 'run(inBackground:)'
CDVBackgroundLocationServices.swift:490:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:495:13: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:497:13: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:517:13: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:522:13: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:530:41: 'High' has been renamed to 'high'
CDVBackgroundLocationServices.swift:533:41: 'Medium' has been renamed to 'medium'
CDVBackgroundLocationServices.swift:536:41: 'Low' has been renamed to 'low'
CDVBackgroundLocationServices.swift:552:51: Missing argument label 'confidence:' in call
CDVBackgroundLocationServices.swift:567:9: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:569:16: Cannot convert return expression of type 'Dictionary<_, _>' to return type 'NSDictionary'
CDVBackgroundLocationServices.swift:578:26: 'init(status:messageAsDictionary:)' has been renamed to 'init(status:messageAs:)'
CDVBackgroundLocationServices.swift:579:25: 'setKeepCallbackAsBool' has been renamed to 'setKeepCallbackAs(_:)'
CDVBackgroundLocationServices.swift:580:42: 'sendPluginResult(_:callbackId:)' has been renamed to 'send(_:callbackId:)'
CDVBackgroundLocationServices.swift:574:38: 'runInBackground' has been renamed to 'run(inBackground:)'
CDVBackgroundLocationServices.swift:594:50: 'NSOperationQueue' has been renamed to 'OperationQueue'
CDVBackgroundLocationServices.swift:614:13: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:644:33: 'sharedApplication()' has been renamed to 'shared()'
CDVBackgroundLocationServices.swift:648:12: Value of type 'UIApplication' has no member 'respondsToSelector'
CDVBackgroundLocationServices.swift:650:17: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:654:17: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:656:17: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:666:30: Missing argument label 'all:' in call
CDVBackgroundLocationServices.swift:670:30: Missing argument label 'all:' in call
CDVBackgroundLocationServices.swift:674:33: 'sharedApplication()' has been renamed to 'shared()'
CDVBackgroundLocationServices.swift:675:12: Value of type 'UIApplication' has no member 'respondsToSelector'
CDVBackgroundLocationServices.swift:680:17: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:682:34: 'removeAtIndex' has been renamed to 'remove'
CDVBackgroundLocationServices.swift:682:34: Result of call to 'removeAtIndex' is unused
CDVBackgroundLocationServices.swift:686:69: Cannot subscript a value of type 'inout [Int]' (aka 'inout Array<Int>')
CDVBackgroundLocationServices.swift:690:17: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:694:17: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:707:13: Cannot invoke 'log' with an argument list of type '(String)'
CDVBackgroundLocationServices.swift:709:37: 'NSTimeZone' has been renamed to 'TimeZone'
CDVBackgroundLocationServices.swift:713:27: 'sharedApplication()' has been renamed to 'shared()'

Ionic help

Im trying to configure it to an ionic app and i cant understand how to use it

Tracking on locked phone

  1. should this be working when my device (android) screen is off? cause I'm having a hard time getting that to work, when app in background and sceen is unlocked all is good.

  2. When not moving it stops tracking to save power, which is awsome. But it never seems to start again, is this by design or am I missing something.

"class not found" error on registerForLocationUpdates ..

I am trying to registerForLocationUpdates, however I do immediately get a "class no found"-error delivered through the error callback.
Am I missing something?
I am on cordova 5.4.1 with ionic and both Google Play Services Google Repository are installed.

No location update when disconnected from charger

Hi,
I've added your plugin to my project and so far it works fine.
It doesn't get location updates when the screen is locked AND it is NOT charging. I'm on Android 6 so I assume that it has something to do with the doze mode but I already disabled it for the app.
Any ideas on what the problem might be?

Error on UWP

I know windows and UWP is not supported, but I'm having an issue. My app supports UWP and i use your plugin on Android and iOS platform. But the way Ionic/cordova works it tries to install plugins on all platforms (even the ones not supported) this works great for other (platform bound) plugins I use but your plugin thows this (which is a big pain in the a.. for me):

Installing "org.flybuy.cordova.background-location-services" for windows
Dependent plugin "cordova-plugin-geolocation" already installed on windows.
Failed to install 'org.flybuy.cordova.background-location-services':CordovaError: Uh oh!
"D:\projects\JobOnTheRun\app-new\plugins\org.flybuy.cordova.background-location-services\com.google.android.gms:play-services-location:+" not found!
    at copyFile (D:\projects\JobOnTheRun\app-new\platforms\windows\cordova\lib\PluginHandler.js:173:36)
    at handlers.framework.install (D:\projects\JobOnTheRun\app-new\platforms\windows\cordova\lib\PluginHandler.js:80:17)
    at Object.ActionStack.process (D:\projects\JobOnTheRun\app-new\platforms\windows\cordova\node_modules\cordova-common\src\ActionStack.js:56:25)
    at Api.addPlugin (D:\projects\JobOnTheRun\app-new\platforms\windows\cordova\Api.js:208:20)
    at handleInstall (C:\Users\tr\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\plugman\install.js:611:6)
    at C:\Users\tr\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\plugman\install.js:407:28
    at _fulfilled (C:\Users\tr\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:787:54)
    at self.promiseDispatch.done (C:\Users\tr\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:816:30)
    at Promise.promise.promiseDispatch (C:\Users\tr\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:749:13)
    at C:\Users\tr\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:509:49Error: Uh oh!
"D:\projects\JobOnTheRun\app-new\plugins\org.flybuy.cordova.background-location-services\com.google.android.gms:play-services-location:+" not found!

Could you by any chance fix it so it just ignores (or install empty plugin or whatever other ppl do) this would be very appreciated.

Please create a standalone activity recognition plugin

I haven't used the plugin yet, but I can see that it has activity recognition built in. It's interesting to note that there isn't any activity recognition cordova plugin for Android out there. It would be really great if you could create a dedicated plugin for that.

If you decide to do so, please let me have the link. Thanks.

background service crashed when app is closed

Hi
I am wondering if I can track location even if the app is closed. Currently after closing app, background service is also get crashed. Please let me know if somehow we can do this.

Service not working in background

Hi, Service is not working when i set app in foreground. Both Service are registerForLocationUpdates and registerForActivityUpdates trigger once in background. using android marshmallow and this is ionic fresh application created to test this service.

Android app demo?

Hi,

Do you have any Android app demo in the Google Play? I want to test it first before start coding.
If possible, can you also share the source code for the demo (Android) app on GitHub?

That will be very helpful for me and others.

Thanks.

sdk support?

What android SDK is the highest this will be compatible with?

iOS build fails on build.phonegap.com

First congratulations for the work, as reported in #14 the plugin seems to work perfectly on Android but in the version for IOS an error occurs when compiling the application by build.phonegap.com, I've tried everything I'm more than a month searching for a solution but unfortunately not found, would be very happy if someone could help the community.

erross

build.phonegap Log Error

=== BUILD TARGET MyApp OF PROJECT MyApp WITH THE DEFAULT CONFIGURATION (Release) ===

Check dependencies
Swift is unavailable on iOS earlier than 7.0; please set IPHONEOS_DEPLOYMENT_TARGET to 7.0 or later (currently it is '6.0').
warning: skipping file '/project/com.google.android.gms:play-services-location:+' (unexpected file type 'file' in Frameworks & Libraries build phase)
warning: skipping file '/project/com.google.android.gms:play-services-location:+' (unexpected file type 'file' in Frameworks & Libraries build phase)

** BUILD FAILED **


The following build commands failed:
    Check dependencies
(1 failure)

**

When upgrading to or 8.0 continues giving error with another code as the log below:**

** BUILD FAILED **

The following build commands failed:
    CompileSwift normal arm64 /project/RumoApp/Plugins/org.flybuy.cordova.background-location-services/CDVBackgroundLocationServices.swift
    CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(2 failures)

When upgrading to <preference name = "deployment-target" value = "7.0" /> or 8.0 continues giving error with another code as the log below:

When updating the version of Phonegap in config.xml <preference name = "phonegap-version" value = "cli-6.1.0" /> the app is finally compiled without errors, but when I try to open the app on the device it opens and closes unexpectedly.

play service location not found

Hi, after launching cordova plugin add https://github.com/pmwisdom/cordova-background-geolocation-services.git I get:

Error: Uh oh!
"workspace_ionic/comeInComo_gps/plugins/org.flybuy.cordova.background-location-services/com.google.android.gms:play-services-location:+" not found!

In sdk manager those modules are correctly installed. Can you help me?

Thank you

Speed and Heading is 0

Hi, In return object from background service always have speed value 0 and heading is also zero. I am using android marshmallow and tried with Battery Optimization true and false but same result.

Tested with Mock Location app in android 6.0 working very fine.

 bgLocationServices.configure({
        //Both
        desiredAccuracy: 15, // Desired Accuracy of the location updates (lower means more accurate but more battery consumption)
        distanceFilter: 5, // (Meters) How far you must move from the last point to trigger a location update
        debug: true, // <-- Enable to show visual indications when you receive a background location update
        interval: 1000, // (Milliseconds) Requested Interval in between location updates.
        useActivityDetection: false, // Uses Activitiy detection to shut off gps when you are still (Greatly enhances Battery Life)

        //Android Only
        notificationTitle: 'Spotter', // customize the title of the notification
        notificationText: 'Watching for you set place.', //customize the text of the notification
        fastestInterval: 5000, // <-- (Milliseconds) Fastest interval your app / server can handle updates

    });

Typo in constant

File .../plugins/org.flybuy.cordova.background-location-services/src/android/BackgroundLocationUpdateService.java

private static final Integer SECONDS_PER_MINUTE      = 60;
private static final Integer MILLISECONDS_PER_SECOND = 1000; // <-- not 60 !

iOS Lock screen tracking

I'm having some issues with tracking when the device is locked and the app is in the foreground on iOS (not tested on Android).

I have been experiencing this in my own app and thought it was perhaps an issue with my own code but I see the same issue when using your demo code in a fresh Phonegap app. Often I do not receive location updates or notifications. When the app resumes I see one "We got an BG update ...." console log. Some times it will work perfectly but I can't work out what is causing the inconsistent behaviour.

Locations seem to work perfectly when the app is pushed into the background with the home button before locking the device.

I am successfully acquiring a location before locking the device.

This is my test index.js

var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicitly call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);

        var output = document.getElementById("output");
        output.textContent = "Getting position...";

        //Make sure to get at least one GPS coordinate in the foreground before starting background services
        navigator.geolocation.getCurrentPosition(onSuccess);

        function onSuccess() {
            output.textContent = "Position aquired.";
        }

        //Get plugin
        var bgLocationServices =  window.plugins.backgroundLocationServices;

        //Congfigure Plugin
        bgLocationServices.configure({
            //Both
            desiredAccuracy: 20, // Desired Accuracy of the location updates (lower means more accurate but more battery consumption)
            distanceFilter: 5, // (Meters) How far you must move from the last point to trigger a location update
            debug: true, // <-- Enable to show visual indications when you receive a background location update
            interval: 9000, // (Milliseconds) Requested Interval in between location updates.
            //Android Only
            notificationTitle: 'BG Plugin', // customize the title of the notification
            notificationText: 'Tracking', //customize the text of the notification
            fastestInterval: 5000, // <-- (Milliseconds) Fastest interval your app / server can handle updates
            useActivityDetection: true // Uses Activitiy detection to shut off gps when you are still (Greatly enhances Battery Life)

        });

        //Register a callback for location updates, this is where location objects will be sent in the background
        bgLocationServices.registerForLocationUpdates(function(location) {
            console.log("We got an BG Update" + JSON.stringify(location));
        }, function(err) {
            console.log("Error: Didnt get an update", err);
        });

        //Register for Activity Updates (ANDROID ONLY)
        //Uses the Detected Activies API to send back an array of activities and their confidence levels
        //See here for more information: //https://developers.google.com/android/reference/com/google/android/gms/location/DetectedActivity
        bgLocationServices.registerForActivityUpdates(function(acitivites) {
            console.log("We got an BG Update" + activities);
        }, function(err) {
            console.log("Error: Something went wrong", err);
        });

        //Start the Background Tracker. When you enter the background tracking will start, and stop when you enter the foreground.
        bgLocationServices.start();


        ///later, to stop
        //bgLocationServices.stop();
    }
};

Here is an example log from a time when tracking did not work:

2016-05-27 13:05:11.012 Hello World[3739:1422193] Apache Cordova native platform version 3.9.2 is starting.
2016-05-27 13:05:11.013 Hello World[3739:1422193] Multi-tasking -> Device: YES, App: YES
2016-05-27 13:05:11.029 Hello World[3739:1422193] Unlimited access to network resources
2016-05-27 13:05:11.042 Hello World[3739:1422193] 

Started backup to iCloud! Please be careful.
Your application might be rejected by Apple if you store too much data.
For more information please read "iOS Data Storage Guidelines" at:
https://developer.apple.com/icloud/documentation/data-storage/
To disable web storage backup to iCloud, set the BackupWebStorage preference to "local" in the Cordova config.xml file

2016-05-27 13:05:11.496 Hello World[3739:1422193] Resetting plugins due to page load.
2016-05-27 13:05:11.637 Hello World[3739:1422193] Finished load of: file:///var/containers/Bundle/Application/11D795EC-B0CD-4025-9E96-862A74025B35/Hello%20World.app/www/index.html
2016-05-27 13:05:11.741 Hello World[3739:1422193] THREAD WARNING: ['Geolocation'] took '21.319092' ms. Plugin should use a background thread.
2016-05-27 13:05:11.774 Hello World[3739:1422193] [LocationServices] - --------------------------------------------------------
2016-05-27 13:05:11.775 Hello World[3739:1422193] [LocationServices] -    Configuration Success
2016-05-27 13:05:11.776 Hello World[3739:1422193] [LocationServices] -        Distance Filter     5.0
2016-05-27 13:05:11.776 Hello World[3739:1422193] [LocationServices] -        Desired Accuracy    10.0
2016-05-27 13:05:11.779 Hello World[3739:1422193] [LocationServices] -        Activity Type       CLActivityType
2016-05-27 13:05:11.779 Hello World[3739:1422193] [LocationServices] -        Update Interval     5.0
2016-05-27 13:05:11.779 Hello World[3739:1422193] [LocationServices] - --------------------------------------------------------
2016-05-27 13:05:11.780 Hello World[3739:1422193] [LocationServices] - Started
2016-05-27 13:05:11.811 Hello World[3739:1422193] THREAD WARNING: ['BackgroundLocationServices'] took '30.446045' ms. Plugin should use a background thread.
2016-05-27 13:05:11.815 Hello World[3739:1422193] [LocationServices] - registerForLocationUpdates
2016-05-27 13:05:11.817 Hello World[3739:1422193] ERROR: Method 'registerForActivityUpdates:' not defined in Plugin 'BackgroundLocationServices'
2016-05-27 13:05:11.817 Hello World[3739:1422193] -[CDVCommandQueue executePending] [Line 159] FAILED pluginJSON = ["BackgroundLocationServices565512988","BackgroundLocationServices","registerForActivityUpdates",[]]
2016-05-27 13:05:16.318 Hello World[3739:1422193] [LocationServices] - App Will Resign. Enabled? true
2016-05-27 13:05:16.320 Hello World[3739:1422193] [LocationServices] - Starting Location Updates!
2016-05-27 13:05:16.409 Hello World[3739:1422193] [LocationServices] - App Suspended. Enabled? true
2016-05-27 13:05:16.412 Hello World[3739:1422193] [LocationServices] - Starting Location Updates!
2016-05-27 13:05:16.425 Hello World[3739:1422193] [LocationServices] - Got location update

AFTER RESUME…

2016-05-27 13:05:39.831 Hello World[3739:1422193] [LocationServices] - sync called
2016-05-27 13:05:39.832 Hello World[3739:1422193] [LocationServices] - locationArray has no entries
2016-05-27 13:05:39.832 Hello World[3739:1422193] [LocationServices] - Stopped Location Updates After 2.0
2016-05-27 13:05:39.832 Hello World[3739:1422193] [LocationServices] - restartUpdates called
2016-05-27 13:05:39.834 Hello World[3739:1422193] [LocationServices] - Starting Location Updates!
2016-05-27 13:05:40.032 Hello World[3739:1422193] [LocationServices] - App Resumed
2016-05-27 13:05:40.037 Hello World[3739:1422193] [LocationServices] - Stopping Location Updates!
2016-05-27 13:05:40.083 Hello World[3739:1422193] [LocationServices] - Got location update
2016-05-27 13:05:40.085 Hello World[3739:1422193] [LocationServices] - Got location update
2016-05-27 13:05:42.084 Hello World[3739:1422193] [LocationServices] - sync called
2016-05-27 13:05:42.106 Hello World[3739:1422193] [LocationServices] - bestLocation: {Optional(<+53.79545628,-1.54111949> +/- 65.00m (speed -1.00 mps / course -1.00) @ 27/05/2016, 13:05:40 British Summer Time)}

SIMILAR TO BELOW IS REPEATED EVERY 2 SECONDS...

2016-05-27 13:10:22.747 Hello World[3745:1424146] [LocationServices] - Got Location Update:  { 53.7954899420689 - -1.54113312728304 }  Accuracy: 65.0
2016-05-27 13:10:22.747 Hello World[3745:1424146] [LocationServices] - Sending Notification
2016-05-27 13:10:22.749 Hello World[3745:1424146] [LocationServices] - Stopped Location Updates After 2.0
2016-05-27 13:10:25.370 Hello World[3745:1424146] [LocationServices] - App Resumed
2016-05-27 13:10:25.370 Hello World[3745:1424146] [LocationServices] - Stopping Location Updates!
2016-05-27 13:10:25.374 Hello World[3745:1424146] [LocationServices] - Got location update
2016-05-27 13:10:27.375 Hello World[3745:1424146] [LocationServices] - sync called
2016-05-27 13:10:27.378 Hello World[3745:1424146] [LocationServices] - bestLocation: {Optional(<+53.79550998,-1.54116128> +/- 65.00m (speed -1.00 mps / course -1.00) @ 27/05/2016, 13:10:25 British Summer Time)}

How to implement typical use-case?

I would like a user to be able to kick off background location (through this plugin), then have them spend some time on WhatsApp or whatever, then move to a second app/web page I write, where they can see the route they travelled as a series of lat/lon or on a map.

Q: How does the background geolocation service communicate the lat/lon coords it received from the phone’s hardware to another (foreground) process?

a) Via memory? Does some sort of shared name space exist on Android or iOS that one process can write to and another can read from? I suspect not.

b) Via a cookie? Don’t think so. Cookie is bound to document.

c) Via a file on the mobile that the background process writes to and the foreground process reads from. Cannot write files in browser js (can in node.js apparently).

d) Via a lightweight database, preferably one that is easy to use with javascript, maybe https://pouchdb.com or http://alasql.org ? Depends on underlying storage mechanism used?

e) Via a web server? The background process could HTTP POST/PUT ( XMLHttpRequest) the coords to a server (which presumably stores this in a db) and the foreground process could GET it from there.

Thoughts anyone?

detect if plugin is running

Hi, i have a button that have on / off text, all is ok with plugin, when i click the button, the text change to ok but whe i want to go to other page and go back to the button page, the button is in off but the plugin is still running, i want to know if there is some way to get the status of the plugin, if hes running to change that value button

When to `start` and `stop`?

Thanks again for your lovely plugin.

From the readme:

//Start the Background Tracker. When you enter the background tracking will start, and stop when you enter the foreground.
bgLocationServices.start();


///later, to stop
bgLocationServices.stop();

I assume that you call start() as soon as you want background location services to engage.

Curious--when would anybody ever call stop()?

The time I can think of is: Right before calling start()...

Are these methods synchronous?

Only retrieves one GPS coordinate in the background.

Possible Causes:

If you did not acquire a GPS coordinates via navigator.geolocation.getCurrentPosition before going into the background this may happen.

Make sure you are starting the GPS plugin before you into the background (don't start it on your on background listener)

If you set a high distance filter and you have not moved.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.