Android-在 onResume() 中获取新位置的最佳方法
我正在开发的应用程序使用 GPS,有时在 onResume 中,当用户重新启动应用程序时,使用的位置非常旧,有时非常远。即使我在位置管理器中将时间设置为 0,它也不会更新。我尝试过使用粗略和精细添加新的侦听器,并从一种切换到另一种,但我仍然无法使其可靠。有人可以向我指出在 onResume 方法中强制更新新位置的最佳、最可靠的方法是什么吗?我不想再依赖lastLocationKnown,因为那是我现在的问题。
编辑:也许我应该问的是如何获得不断更新的位置。看来您只能将您的位置设置为“lastKnown”,这给我带来了问题。
The app Im working on uses gps and sometimes in the onResume when the user restarts the app the location used is very old and sometimes very far away. It also will not update even when I have set the time to 0 in my location manager. Ive tried adding new listeners using both coarse and fine and switching from one to the other but I still cant get it to be reliable. Can some one point out to me what the best most reliable way to force a new location update in the onResume method. I no longer want to rely on lastLocationKnown as that is my problem now.
Edit: Maybe what I should have asked is how do I get a location that is constatly updated. It seems like you can only set your location as lastKnown which is giving me problems.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了类似的问题,并意识到
onProviderEnabled()
不会立即调用onResume()
。我最终没有在onPause()
中取消注册侦听器,而是在onDestroy()
中取消注册它们。以下是相关文档的链接:
http://developer.android.com/reference/android/location/LocationListener。 html
这是我最初的 Stack Overflow 问题的链接:
为什么 Android 的 onProviderEnabled() 方法没有被调用?
希望如此有帮助。梅尔
I had a similar problem, and realised that
onProviderEnabled()
is not immediately calledonResume()
. I ended up not unregstering my listeners inonPause()
, but instead unregistered them inonDestroy()
.Here is the link to the relevant documentation:
http://developer.android.com/reference/android/location/LocationListener.html
Here is the link to my original Stack Overflow question:
Why isn't Android's onProviderEnabled() method being called?
Hope this helps. Mel