Android 4.2 OS電話でアプリを実行すると、getLAstKnownLocationから返される値を取得できないようです(常にnull)。奇妙なことに、Mapviewは正常に機能し、現在の場所が表示されます。
この問題を解決する方法はありますか?
これが私のコードです
onCreateで:
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");
}
}