离子:背景地理位置 [英] Ionic: background geolocation

查看:101
本文介绍了离子:背景地理位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ionic&Firebase创建用于地理位置的Android应用程序.我使用 ngCordova.geolocation 并成功获取了设备的当前位置.

I'm using Ionic & Firebase to create an Android application for geolocation. I used ngCordova.geolocation and I successfully get the device current location.

我的问题是,只要用户没有关闭地理位置并在每次地理位置更改时都回调函数,我就需要连续获取当前位置,并测试用户是否在地图上的多个圆圈中

My problem is that I need to continuously get current location, as long as the user doesn't turn off geolocation and callback a function every time the geolocation change, and test if the user is inside one of many circles in the maps.

推荐答案

由于您已经在使用ngcordova.geolocation插件,因此它具有一种通过

Since you are already using the ngcordova.geolocation plugin, it has a method to keep tracking the device position via watchPosition. There's an example in the docs indicating how to use it:

  var watchOptions = {
    timeout : 3000,
    enableHighAccuracy: false // may cause errors if true
  };

  var watch = $cordovaGeolocation.watchPosition(watchOptions);
  watch.then(
    null,
    function(err) {
      // error
    },
    function(position) {
      var lat  = position.coords.latitude
      var long = position.coords.longitude

      /* Further code to execute on each update */
  });

这篇关于离子:背景地理位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆