Geting Speed From GPS on Android Calculating Distance And Time

我的梦境 提交于 2019-12-01 21:16:38
znat

I am wondering if your implementation is correct. I think the problem is that the location updates are not connected to the fix of a new location. So if your gps did not make a new fix, then the current location will be sent again.

A logic could be that every X seconds, you turn on your requestLocationUpdates() process the location if/when it is received and turn off updates (removeUpdates()) Check this post for an excellent example (that solved many problems for me): What is the simplest and most robust way to get the user's current location on Android?

The example above is clear to understand. The tricky part is to use it in a service as a service does not work when the phone goes on sleep mode. Here you can use a commonsware component to overcome this.

I have used and mixed those two components to set up a location service and it is stable.

Hope it helps

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