当我在 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");
}
}