2012-11-25 1 views
3

Android 4.2 OS 폰에서 내 앱을 실행할 때 getLAstKnownLocation (항상 null)에서 반환 된 값을 가져올 수없는 것 같습니다. 이상한 점은 Mapview가 제대로 작동한다는 것입니다. 내 현재 위치를 보여줍니다 !!Android 4.2 위치 서비스 문제

어떤 아이디어로이 문제를 해결할 수 있습니까?

mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
Criteria criteria = new Criteria(); 
provider = mlocManager.getBestProvider(criteria, false); 
mlocManager.requestLocationUpdates(provider, 0, 0, geoHandler); 

후 청취자 : 공급자가 비활성화 된 경우

public class GeoUpdateHandler implements LocationListener { 
    public void onLocationChanged(Location location) { 
     // called when the listener is notified with a location update from the GPS 
     int lat = (int) (location.getLatitude() * 1E6); 
     int lng = (int) (location.getLongitude() * 1E6); 
     new GeoPoint(lat, lng); 

     Log.d(this.getClass().getSimpleName(), "onLocationChanged " + lat); 
     //   mlocManager.removeUpdates(this); 
    } 

    public void onProviderDisabled(String provider) { 
     // called when the GPS provider is turned off (user turning off the GPS on the phone) 
     Log.d(TAG, "DISABLED"); 
    } 

    public void onProviderEnabled(String provider) { 
     // called when the GPS provider is turned on (user turning on the GPS on the phone) 
     Log.d(TAG, "ENABLED"); 
    } 

    public void onStatusChanged(String provider, int status, Bundle extras) { 
     // called when the status of the GPS provider changes 
     Log.d(TAG, "CHANGED"); 
    } 
} 

답변

0

getLastKnownLocation이 널 (null)을 반환합니다

여기 내 코드에서 onCreate에서

입니다. 또는 LastKnownLocation이없는 경우. provider = mlocManager.getBestProvider(criteria, false);

공급자가 비활성화 제공을 포함하여 BestProvider 요구된다 라인에

. 진술의 끝 부분에서 true를 사용하여 작동하는지 확인하십시오.

http://developer.android.com/reference/android/location/LocationManager.html#getLastKnownLocation(java.lang.String)

+0

답해 주셔서 감사합니다. "true"로 설정하고 위의 다음 행을 추가하면 작동합니다. \t \t \t \t \t \t criteria.setAccuracy (Criteria.ACCURACY_FINE); – AlAsiri