2012-03-26 83 views
1

我能在我的設備中的GPS,但我沒有得到的位置:Android的GPS定位

LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
if(lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) 
{ 
    Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
    if(location!=null) 
    { 
     showCurrentAddress(location); 
    } 
} 

但在這裏,我剛開位置是空,我增加了以下權限我的代碼:

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

你能幫忙嗎?

+2

試試這個[鏈接] [ 1] [1]:http://stackoverflow.com/questions/3145089/what-is-the-simplest-and-most-robust-way-to-get-the-users-current- 3145655#3145655 討論獲取GP位置 – Dinesh 2012-03-26 08:15:32

+0

試試這個[link] [1] [1]:http://stackoverflow.com/questions/3145089/what-is-the-simplest-and-most-robust-way-to-get-the-users-current-location- IN-A/3145655#3145655 – Dinesh 2012-03-26 09:08:11

回答

1

lm.getLastKnownLocation可以返回null,因爲這是最後一個已知位置的吸氣劑。

嘗試使用lm.requestLocationUpdates(LocationListener)