【问题标题】:cordova-ionic app take geolocation in background - android and ioscordova-ionic 应用程序在后台进行地理定位 - android 和 ios
【发布时间】:2015-08-13 21:12:44
【问题描述】:

我想使用 cordova 和 ionic 构建一个能够提供地理定位的应用程序。根据我的研究,当应用程序在后台运行时提供有关地理位置的信息存在一些问题。您能否就如何解决此问题提供任何提示或建议?谢谢 :D

【问题讨论】:

    标签: android ios cordova geolocation ionic


    【解决方案1】:

    当然,使用此插件可以进行后台地理定位:cordova-plugin-background-geolocation

    添加 ngCordova 以通过 AngularJS 包装器与插件交互。

    ngCordovacordova-plugin-background-geolocation 的示例(来自 ngCordova 文档的示例):

    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);
    });
    

    【讨论】:

    • 我刚刚安装了插件和 ngCordova,我想用这个例子进行测试....请告诉我,如果我包括这个---->>desiredAccuracy: 10,stationaryRadius:20, distanceFilter: 30, notificationTitle: 'Background tracking', //
    • 是的,将其添加到选项对象应该允许您测试插件。您必须尝试各种选项才能找到适用于您的应用的值。
    • 嗨...我将“geolocation-background”包装在我的“$ionicPlatform.ready(function()”中并且似乎可以工作。我使用了这个解决方案,因为使用 ngCordova“设备就绪功能”没有t 工作。但是,因为这个函数超出了“$scope”覆盖(超出 app.controller),我的问题是,我怎样才能检测到这个函数中的点击事件?谢谢......我希望得到很好的解释: )))
    • 您可以在控制器中使用$ionicPlatform.ready()。请务必将其包含在您的控制器定义中:module.controller('MyCtrl', function($scope, $ionicPlatform, $cordovaBackgroundGeolocation).
    • 没问题,很高兴听到您成功了。祝你的项目好运。
    猜你喜欢
    • 2016-01-11
    • 2017-09-23
    • 2017-03-03
    • 1970-01-01
    • 2022-01-16
    • 2022-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多