离子:背景地理位置 [英] Ionic: background geolocation
问题描述
我正在使用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屋!