Update GPS Listener every 5 seconds(每 5 秒更新一次 GPS 监听器)
问题描述
我应该每 5 秒更新一次侦听器.但事实并非如此.我的代码可能有什么问题?
I'm supposed to update the listener every 5 seconds. But it doesn't. What could be wrong with my code?
非常感谢您的帮助!
推荐答案
将其设置为 5000 毫秒并不一定意味着您将每 5 秒获取一次位置.时间或多或少是最好的情况.
By setting it to 5000 ms it doesn't necessarily mean that you will get the location every 5th second. The time is more or less a best case scenario.
minTime 通知的最小时间间隔,以毫秒为单位.此字段仅用作节省电量的提示,位置更新之间的实际时间可能大于或小于此值.http://developer.android.com/reference/android/location/LocationManager.html
minTime the minimum time interval for notifications, in milliseconds. This field is only used as a hint to conserve power, and actual time between location updates may be greater or lesser than this value. http://developer.android.com/reference/android/location/LocationManager.html
您确定您的活动正在运行吗?如果您想在活动处于休眠状态时接收位置,则需要唤醒锁和服务.
Are you sure you have your activity running? If you want to recieve the location when the activity is sleeping you need a wake lock and a service.
例如,在我创建的 GPS 应用程序中,我设置了 0 毫秒来尽快获取它,但在调试和检查 logcat 时,我有时每分钟左右获取一次位置,而不是每秒获取一次.
For example in a GPS app I created I put 0 ms to get it as soon as possible but when debugging and checking the logcat I sometimes get the location every minute or so, not every second.
这篇关于每 5 秒更新一次 GPS 监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!