Android GPS My Location finding

≡放荡痞女 提交于 2019-11-29 18:14:45

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!