Android GPS 我的位置查找

Android GPS My Location finding(Android GPS 我的位置查找)
本文介绍了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?

推荐答案

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

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"/>

但通常 GPS 仅适用于空旷的天空(在室内不太好).因此,虽然 Google 地图可能会显示最后一个已知位置,但您的应用可能不会.因此,您可能希望最初调用 getLastKnowLocation 来设置初始标记.即使 GPS 无法修复,您仍然可以显示设备已知的最后一个已知位置,即您上次在户外的时间.

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.

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

Alternatively or additionally to GPS_Provider, you could also use the

LocationManager.NETWORK_PROVIDER

相反,它基于 Wifi 和/或 GMS,不如 GPS 准确,但在室内工作.

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

为此,您需要权限

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

在您的清单中.

这篇关于Android GPS 我的位置查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)
4