安卓LocationManager.requestLocationUpdates与minTime大于0工作不正常 [英] android LocationManager.requestLocationUpdates with minTime >0 not working as expected

查看:464
本文介绍了安卓LocationManager.requestLocationUpdates与minTime大于0工作不正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置


locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 0f, this);

它有一个奇怪的行为,locationChanged被称为每一秒中的任何时间接近1分钟来代替。其次,locationChanged被调用每秒像10秒钟,然后完全停止,GPS satalites图标消失,那么只有重新恢复时,屏幕会返回从显示超时。
出了什么问题?

it has an odd behavior, locationChanged gets called every second instead of any time close to 1 minute. Secondly, locationChanged gets called every second for like 10 seconds, then stops completely, the gps satalites icon disappears, then only resumes again when the screen returns from display timeout.
what's wrong?

我目前是在Android 1.5。

I'm currently on android 1.5.

推荐答案

在minTime(60000)仅仅是一个暗示,而且也不能保证你的LocationListener的将踢在一个确切的1分钟间隔。结合minDistance依旧= 0时,你可能会收到更多的更新。

The minTime (60000) is just a hint, and there's no guarantee that your locationlistener will kick in at an exact 1 minute interval. Combined with the minDistance=0, you'll probably receive a lot more updates.

我会增加minDistance依旧1米最低,并实现补偿逻辑来实现你的code 1分钟的间隔。你LocationListener的可以以这样的方式,如果位置更新过近,它们将被忽略并且不处理来实现。

I would increase the minDistance to 1m minimum, and implement compensation logic to achieve the 1 minute interval in your code. You LocationListener can be implemented in such a way that if location updates follow too closely, they are ignored and not processed.

您还将获得不同的地点通过你的位置监听器,具有不同的精度,都在这分钟间隔。

You'll also get different locations through your location listener, with a different accuracy, all within that minute interval.

您的位置监听器可以挑选最好的准确性,还记得上次的位置被保持状态(lastLocationProcessedAt)处理。

Your location listener can pick the best accuracy, and remember when the last location was processed by maintaining state (lastLocationProcessedAt).

有关更多信息,结账<一href="http://blog.doityourselfandroid.com/2010/12/25/understanding-locationlistener-android/">Understanding在LocationListener的Andr​​oid中。

这篇关于安卓LocationManager.requestLocationUpdates与minTime大于0工作不正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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