屏幕锁定时的 navigator.geolocation.getCurrentPosition() [英] navigator.geolocation.getCurrentPosition() when screen is locked

查看:43
本文介绍了屏幕锁定时的 navigator.geolocation.getCurrentPosition()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,当它处于旅行模式时,它会不断地轮询位置.我的问题是,一旦屏幕被锁定,应用程序就无法再通过手机访问地理位置.

I have an App which constantly polls for location when its in travelling mode. My issue is that once the screen is locked, the App can no longer access the geolocation from the phone.

我设法找到了这个插件,但它需要我购买它才能在 Android 中工作.http://shop.transistorsoft.com/pages/cordova-background-geolocation-premium

I have managed to find this plugin but it requires I purchase it for the capability to work in Android. http://shop.transistorsoft.com/pages/cordova-background-geolocation-premium

有谁知道是否有一个免费选项可以让我在屏幕锁定时在 Ionic/Cordova 应用程序中获取位置以成功轮询?

Does anyone know if there is a free option that i can use to get location to successfully poll in an Ionic / Cordova application while the screen is locked?

推荐答案

另一种选择是使用 部分唤醒锁 可让您的应用在后台(屏幕关闭或切换出前台)时保持活跃.您需要通过插件来执行此操作,但它与后台服务具有相同的效果,让您的应用程序保持活动状态,以便在后台接收位置更新.

Another option is to use a partial wakelock on Android to keep your app alive while in the background (screen off or switched out of foreground). You'd need to do this via a plugin, but it would have the same effect as a background service, keeping you app alive to receive location updates while in the background.

有关 Cordova 2.0 的源代码,请参阅我的旧答案插件(需要更新 Cordova 3+).

See my old answer here for the source code for a Cordova 2.0 plugin (it will need updating for Cordova 3+).

这篇关于屏幕锁定时的 navigator.geolocation.getCurrentPosition()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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