2012-03-26 12 views
1

私は私のデバイスでGPSを有効にしますが、私はloactionを取得していない午前: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); 
    } 
} 

しかし、ここで私はgettinの場所がnullであると私は私のコードに次の権限を追加しました:

<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についてGPの場所を取得する – Dinesh

+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

答えて

1

lm.getLastKnownLocationは、最後の既知の場所のゲッターであるため、nullを返すことができます。

lm.requestLocationUpdates(LocationListener)をお試しください。

0

こんにちはGPSの位置については、このチュートリアルをチェックし、私はまた、緯度と経度Using GPS to get current location – Android tutorialチェックこれはあなたのデバイス上ではないエミュレータ上の最初の時間はほんの数秒待つを取得するため、このコードを使用しています。..

関連する問題