Android GPS 我的位置查找
我正在使用此代码找到我当前的位置。但如果我在家,它就找不到我。但谷歌地图和其他类似的应用程序可以找到我,尽管我在家。有什么区别?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 GPS_Provider,请确保您的应用程序清单中具有以下权限:
但通常 GPS 仅适用于自由天空(在室内效果不佳)。因此,虽然 Google 地图可能会显示最后的已知位置,但您的应用程序可能不会。因此,您可能希望首先调用
getLastKnowLocation
来设置初始标记。即使 GPS 无法修复,您仍然可以显示设备已知的最后已知位置,即您上次在户外时的位置。
作为 GPS_Provider 的替代方案或补充,您还可以使用
基于 Wifi 和/或 GMS 的替代方案,其精度不如 GPS,但可在室内工作。
为此,您需要
清单中的许可。
If you're using the GPS_Provider, make sure that you have the following permission in your app manifest:
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
instead,which is based on Wifi and/or GMS, is less accurate than GPS but works indoors.
For this, you need the permission
in your manifest.