Navigator.geolocation.getCurrentPosition () when the screen is locked

I have an application that constantly checks the location when it is in travel mode. My problem is that after the screen is locked, the application can no longer access geolocation from the phone.

I managed to find this plugin, but it requires me to buy it to work on Android. http://shop.transistorsoft.com/pages/cordova-background-geolocation-premium

Does anyone know if there is a free option that I can use to get a place for a successful poll in the Ionic / Cordova app when the screen is locked?

+2
source share
2 answers

Another option is to use partial wakelock on Android to keep your application in the background (the screen is off or on in the foreground). You will need to do this with the plugin, but it will have the same effect as the background service, supporting your application to receive location updates in the background.

See my old answer here for the source code for the Cordova 2.0 plugin (Cordoba 3+ requires an update).

+2
source

Have you watched NG-Cordova ?

first add ng-cordova to your project:

bower install ngCordova or <script src="lib/ngCordova/dist/ng-cordova.js"></script> <script src="cordova.js"></script> 

Then enter:

 angular.module('myApp', ['ngCordova']) 

Here is a plugin that you could try: http://ngcordova.com/docs/plugins/backgroundGeolocation/

just install the plugin:

 cordova plugin add https://github.com/christocracy/cordova-plugin-background-geolocation.git 

then tie it to the controller:

 module.controller('MyCtrl', function($scope, $cordovaBackgroundGeolocation) { var options = { // https://github.com/christocracy/cordova-plugin-background-geolocation#config }; document.addEventListener("deviceready", function () { // `configure` calls `start` internally $cordovaBackgroundGeolocation.configure(options) .then( null, // Background never resolves function (err) { // error callback console.error(err); }, function (location) { // notify callback console.log(location); }); $scope.stopBackgroundGeolocation = function () { $cordovaBackgroundGeolocation.stop(); }; }, false); }); 
+3
source

All Articles