android LocationManager.requestLocationUpdates with minTime >0 not working as expected

人走茶凉 提交于 2019-12-18 07:06:57

问题


I set

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

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?

I'm currently on android 1.5.


回答1:


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.

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.

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



来源:https://stackoverflow.com/questions/4245193/android-locationmanager-requestlocationupdates-with-mintime-0-not-working-as-ex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!