navigator.geolocation.getCurrentPosition() when screen is locked

后端 未结 2 1334
离开以前
离开以前 2021-01-22 21:18

I have an App which constantly polls for location when its in travelling mode. My issue is that once the screen is locked, the App can no longer access the geolocation from the

2条回答
  •  不思量自难忘°
    2021-01-22 22:18

    Have you looked at NG-Cordova?

    first add ng-cordova to your project:

    bower install ngCordova
    
    or
    
    
    
    

    Then inject it:

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

    Here is a plugin 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 bind it to a 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);
        });
    

提交回复
热议问题