Update GPS Listener every 5 seconds

萝らか妹 提交于 2019-12-02 06:39:47

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 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.

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.

As stated by David Olsson, MINIMUM_TIME_BETWEEN_UPDATES only prevents the listener to be requested too often. If you want to regularly requestLocationUpdates, you should use Timer and TimerTask and have requestLocationUpdates run once every 5 seconds

schedule(TimerTask task, long delay, long period)
Schedules the specified task for repeated fixed-delay execution, beginning after the specified delay.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!