简体   繁体   English

Cordova-ionic应用程序在后台进行地理位置定位-Android和iOS

[英]cordova-ionic app take geolocation in background - android and ios

I want to build an app, using cordova and ionic, that is capable to provide geolocation. 我想使用cordova和ionic来构建一个能够提供地理位置的应用程序。 According to my research there are some issues with providing information about geolocation when the app is running in background. 根据我的研究,当应用程序在后台运行时,提供有关地理位置的信息存在一些问题。 Can you give any hints or advice about how can I resolve this? 您能提供任何有关如何解决此问题的提示或建议吗? Thank you :D 谢谢你:D

Sure, background geolocation is possible with this plugin: cordova-plugin-background-geolocation . 当然,使用此插件可以进行背景地理定位: cordova-plugin-background-geolocation

Add ngCordova to interact with the plugin via AngularJS wrappers. 添加ngCordova以通过AngularJS包装器与插件交互。

Example with ngCordova & cordova-plugin-background-geolocation (example from ngCordova Docs): ngCordovacordova-plugin-background-geolocation的示例(来自ngCordova Docs的示例):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM