【问题标题】:GPS position when mobile app is in background (with ionicframework)移动应用程序在后台时的 GPS 位置(使用 ionicframework)
【发布时间】:2015-09-04 14:18:33
【问题描述】:

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

【问题讨论】:

标签: gps ionic-framework


【解决方案1】:

我刚刚写完一个新的适用于 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();

});

【讨论】:

  • 请在此处包含一些示例用法。
  • 您想要什么样的样本用法? github repo 显示了使用细节。
  • @Mirrorcell:很棒的插件...像 Charm 一样工作 :) 但我真正担心的是当用户从最后访问的应用程序列表中删除/杀死应用程序时(通过在 android 手机上按最右边的方形图标..它显示所有列出的)。它不起作用。它应该可以工作......就像Whatsapp或GMap......请纠正我。谢谢
  • 嗨@Niks,在应用程序被强制关闭后跟踪不起作用。 WhatsApp 和 Google 地图如何以这种方式工作?例如,如果我强制关闭 Google 地图,我的手机就会停止跟踪。
【解决方案2】:

您所说的插件可能是 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

目前,其他不同的版本不存在,其他一切都只是这个原始插件的一个分支。

【讨论】:

  • 我正在尝试使用您提供的插件进行后台地理定位。但我收到通知闪烁为“背景地理位置:无效许可证”。你能帮我解决它吗?如果您需要有关我的脚本的更多信息,请告诉我。提前致谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-24
相关资源
最近更新 更多