Zio*_*dda 5 gps ionic-framework
我需要实现一个应用程序,当他从A移动到B时存储用户旅程(路径).现在,我知道离子框架可以使用GPS,但是当我的APP转到后台时会发生什么?我的应用程序如何继续存储用户位置?这可能吗 ?我可以使用插件(不是600美元以上)吗?
我刚刚为ios和android编写了一个新的cordova背景地理定位插件,它的免费和简单!试试看:
https://github.com/pmwisdom/cordova-background-geolocation-services
离子用法:
//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();
});
Run Code Online (Sandbox Code Playgroud)
使用您提到的 600 美元以上高级插件的插件是可能的。
人们通常会忘记旧版本也可用,包括最后可行的 Android/iOS 版本:https://github.com/christocracy/cordova-plugin-background-geolocation/tree/0.3.7
ionic plugin add cordova-plugin-background-geolocation@1.0.5
Run Code Online (Sandbox Code Playgroud)
目前,不存在其他不同的版本,其他所有内容都只是这个原始插件的一个分支。
| 归档时间: |
|
| 查看次数: |
12513 次 |
| 最近记录: |