Android GPS 我的位置查找

发布于 2024-09-12 11:34:34 字数 191 浏览 3 评论 0原文

我正在使用此代码找到我当前的位置。但如果我在家,它就找不到我。但谷歌地图和其他类似的应用程序可以找到我,尽管我在家。有什么区别?

I'm using this code to find my current location. But if I'm at home it can't locate me. But google maps and another similar applications can locate me although I'm at home. What is difference?

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

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

发布评论

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

评论(1

陈年往事 2024-09-19 11:34:34

如果您使用 GPS_Provider,请确保您的应用程序清单中具有以下权限:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

但通常 GPS 仅适用于自由天空(在室内效果不佳)。因此,虽然 Google 地图可能会显示最后的已知位置,但您的应用程序可能不会。因此,您可能希望首先调用 getLastKnowLocation 来设置初始标记。
即使 GPS 无法修复,您仍然可以显示设备已知的最后已知位置,即您上次在户外时的位置。

作为 GPS_Provider 的替代方案或补充,您还可以使用

LocationManager.NETWORK_PROVIDER

基于 Wifi 和/或 GMS 的替代方案,其精度不如 GPS,但可在室内工作。

为此,您需要

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

清单中的许可。

If you're using the GPS_Provider, make sure that you have the following permission in your app manifest:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

But usually GPS only works with a free sky (not indoors very well). Therefore while Google Maps might show the last known location, maybe your app doesn't. So you might want to initially call getLastKnowLocation initially to set the initial marker.
Even though GPS cannot get a fix, you could still show the last known location known to the device, i.e. when you were outdoors last time.

Alternatively or additionally to GPS_Provider, you could also use the

LocationManager.NETWORK_PROVIDER

instead,which is based on Wifi and/or GMS, is less accurate than GPS but works indoors.

For this, you need the permission

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

in your manifest.

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