Android 中的位置提供程序?

发布于 2024-09-14 08:29:09 字数 313 浏览 1 评论 0原文

我的应用程序需要用户的当前位置。为此,我已经实现了代码,并且能够获取当前位置。该代码首先尝试获取最佳提供商,然后获取位置信息。问题是,如果禁用 GPS_PROVIDER,则当前位置将从 NETWORK_PROVIDER 返回。如果同时启用 NETWORK_PROVIDER 和 GPS_PROVIDER,则最好的提供商将是 GPS_PROVIDER,这会花费太多时间来获取当前位置。

那么,如果我们只将位置提供程序设置为NETWORK_PROVIDER,这样GPS_PROVIDER是否启用就无关紧要了。

请让我知道什么是正确的方法。

问候

苏尼尔

My application requires current location of the user. For this I have implemented the code and I am able to get the current location. The code tries to get the best provider first and then fetches location information. The problem is that the current location is returned from NETWORK_PROVIDER if GPS_PROVIDER is disabled. If both NETWORK_PROVIDER and GPS_PROVIDER are enabled then the best provider will be GPS_PROVIDER and this takes too much time to get the current location.

So, is it alright if we set the location provider as NETWORK_PROVIDER only so that it will not matter whether GPS_PROVIDER is enabled or not.

Please let me know what is the right approach.

Regards

Sunil

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

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

发布评论

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

评论(2

滿滿的愛 2024-09-21 08:29:16

GPS 提供比网络提供商更好的精度。

网络提供商是使用蜂窝塔和 WiFi 的三角测量来完成的。

因此,如果您立即需要,请从“最后已知位置”开始,然后切换到网络,一旦您从 GPS 获得修复,就开始使用它。

问候,
维奈

GPS gives better precision than Network provider.

Network provider is done using triangulation of cell towers and wifi.

So, if you need immediately, start with "last known location" then switch to network, once you have the fix from the gps, start using it.

regards,
vinay

鱼忆七猫命九 2024-09-21 08:29:14

根据您的应用程序,您可能只能使用网络位置。对于许多基于位置的服务来说,这已经足够细粒度了。另外,您不必担心 GPS 无线电会耗尽用户的电池。

但如果您确实想要尽可能准确的位置,为什么不听取两家提供商的意见呢?您可以使用 getLastKnownLocation() 方法获取初始位置。然后您可以使用 NETWORK_PROVIDER 位置。然后,一旦从 GPS_PROVIDER 获得修复,您就可以忽略或删除网络侦听器。

Depending on your application, you might be able to use just the network location. This is fine-grained enough for many location-based services. Plus you don't have to worry about sucking up the user's battery with GPS radio.

But if you really want as accurate a location as possible, why not listen to both providers? You could use the getLastKnownLocation() method for the initial location. Then you can use the NETWORK_PROVIDER location. Then, as soon as you get a fix from the GPS_PROVIDER, you can ignore or remove the network listener.

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