Android requestLocationUpdates minimumtime + minimumdistance don't really work

强颜欢笑 提交于 2020-01-15 10:46:05

问题


locationmanager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationlistener);

I understand that this line of code is supposed to update the device location as frequently as possible right? Specifically, every 0miliseconds and 0metres (minimum).

Okay, the word 'minimum' is key here but still, why sometimes the location is not updated for maybe as long as 30+ seconds? I have timed the actual time between one update and the next, while on WiFi, and it took 38 seconds even though I had 0 and 0 in the code. I even tried it with 1000ms (1second) but still doesn't update as frequent.

How do I make this update more frequently? Why does it respond this way?

Thank you!


回答1:


The short answer is: you can't (make it update more frequently).

The documentation indicates that you will get "updates as frequently as possible" if you specify min_distance and min_time as zero. So what you are seeing is "as frequently as possible". Usually you won't get an update unless something has changed, so if you aren't moving you won't necessarily get an update. Also, since you are using Network location and not GPS, the accuracy of locations isn't that good so you shouldn't expect updates that frequently.

Also, each hardware vendor implements the location providers differently. So the frequency of updates is determined by the hardware vendor's implementation.



来源:https://stackoverflow.com/questions/10484239/android-requestlocationupdates-minimumtime-minimumdistance-dont-really-work

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