移动应用程序在后台时的GPS位置(使用离子框架) [英] GPS position when mobile app is in background (with ionicframework)

查看:103
本文介绍了移动应用程序在后台时的GPS位置(使用离子框架)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实现一个存储用户旅程(路径)的应用程序,当他从A移动到B.现在,我知道离子框架可以使用GPS,但是当我的APP进入背景时会发生什么?我的应用程序如何继续存储用户位置?这可能吗 ?有没有插件(不是600美元),我可以使用?

我刚刚完成了一个新的科尔多瓦背景地理定位插件ios和android,它的免费和简单!试试看:



https: //github.com/pmwisdom/cordova-background-geolocation-services



离子用法:

  //等待cordova / ionic准备好使用插件
ionic.Platform.ready(function(){
//确保获得至少一个在开始后台服务之前,前景中的GPS坐标
navigator.geolocation.getCurrentPosition();

// 1.获取插件
var bgLocationServices = window.plugins.backgroundLocationServices;

// 2。配置插件
bgLocationServices.configure({
desiredAccuracy:20,
distanceFilter:5,
notificationTitle:'BG Plugin',
notificationText:'Tracking',
debug:true,
interval:9000,
fasterInterval:5000
});

// 3。注册位置更新的回调,这是位置对象将在后台发送的位置
bgLocationServices.registerForLocationUpdates(function(location){
console.log(We got a BG Update+ JSON.stringify(位置));
},函数(err){
console.log(错误:没有得到更新,错误);
});

// 4。启动后台跟踪器。当你进入后台时,追踪将开始,并在你进入前台时停止。
bgLocationServices.start();


///稍后,停止
bgLocationServices.stop();

});


I need to realize an app that store user journey (path) when he moves from A to B. Now, I know that ionicframework can use GPS, but what happen when my APP go to background ? How can my app continue to store user position ? Is this possible ? Are there plugins (not $600+ please) that I can use ?

解决方案

I just finished writing a new cordova background geolocation plugin for ios and android, its free and simple! try it out:

https://github.com/pmwisdom/cordova-background-geolocation-services

Ionic Usage :

//Wait for cordova / ionic ready to use the plugin
ionic.Platform.ready(function(){
    //Make sure to get at least one GPS coordinate in the foreground before starting background services
    navigator.geolocation.getCurrentPosition();

    //1. Get plugin
    var bgLocationServices =  window.plugins.backgroundLocationServices;

    //2. Configure Plugin
    bgLocationServices.configure({
         desiredAccuracy: 20, 
         distanceFilter: 5, 
         notificationTitle: 'BG Plugin', 
         notificationText: 'Tracking',
         debug: true, 
         interval: 9000, 
         fastestInterval: 5000
    });

    //3. Register a callback for location updates, this is where location objects will be sent in the background
    bgLocationServices.registerForLocationUpdates(function(location) {
         console.log("We got a BG Update" + JSON.stringify(location));
    }, function(err) {
         console.log("Error: Didn't get an update", err);
    });

    //4. Start the Background Tracker. When you enter the background tracking will start, and stop when you enter the foreground.
    bgLocationServices.start();


    ///later, to stop
    bgLocationServices.stop();

});

这篇关于移动应用程序在后台时的GPS位置(使用离子框架)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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