开发者

Android GPS My Location finding

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜