LocationManager 最佳实施?

发布于 2024-10-19 03:54:06 字数 368 浏览 7 评论 0原文

是否建议使用不同的侦听器实现 LocationManager.NETWORK_PROVIDER 和 LocationManager.GPS_PROVIDER ,然后取消注册侦听器 locationManager.removeUpdates(locationListener) ?

因为 GPS_PROVIDER 需要很多时间来返回值,有时甚至不回电?

另外,我们可以有一个 locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);在带有 postDelayed 的处理程序中以避免在没有任何回调的情况下出现死锁?

有人帮忙吗?

提前致谢!!!

BR, J

Is it advisable to implement both LocationManager.NETWORK_PROVIDER and LocationManager.GPS_PROVIDER with the differenct listener and then unregister the listeners locationManager.removeUpdates(locationListener) ?

Because GPS_PROVIDER takes lot of time to return the values and sometimes doesn't even gives a call back?

Also, we can have a locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); in handler with a postDelayed to avoid a deadlock in case there aren't any callbacks?

Any help by anyone?

Thanks in advance!!!

BR,
J

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青衫负雪 2024-10-26 03:54:06

嗯,据我所知,locationManager.getLastKnownLocation 会立即返回,所以您不应该看到任何死锁?

如果您确实需要管理自己的 LocationListener,建议首先注册一个 Network-One 和两个 GPS-One。使用网络监听器接收第一个位置(粗略)。配置一个 GPS 位置侦听器以接收所有 GPS 更新。一旦位置足够准确,切换到托管 GPS 位置监听器,该监听器仅每 x 秒和 x 米差接收更新。请参阅http://developer.android.com/guide/topics/ location/obtaining-user-location.html 了解更多示例。

如果您想在地图上显示位置,请尝试 MyLocationOverlay。它为您完成这一切。

Hm afaik locationManager.getLastKnownLocation returns instantly, so you should not see any deadlocks?

If you really need to manage your own LocationListeners, it is advisable to first register a Network-One and a two GPS-ones. Use the network-Listener to receive a first location (rough). Configure one GPS-Location-listener to receive all GPS-Updates. Once the location is accurate neough, switch to a managed GPS-Location-Listener, that only receives updates every x seconds and x meters diff. See http://developer.android.com/guide/topics/location/obtaining-user-location.html for more examples.

If you want to display the location on a map, try MyLocationOverlay. It does all that for you.

请持续率性 2024-10-26 03:54:06

理想情况下,这个问题将不再有效,因为谷歌最终发布了新版本的位置侦听器,这将更有效地解决这个问题。
链接如下:
http://developer.android.com/google/play-services/location.html

Ideally this question wont be valid anymore, since Google finally released newer version of location listeners which would take care of this more effectively.
Link for the same below:
http://developer.android.com/google/play-services/location.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文