在我的地图应用程序中,我似乎没有获得位置更新,我上了车并开始四处行驶,但我的位置标记在地图上从未改变,甚至给了我一个null lat and long
locationManager = (LocationManager) this.getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
String provider = locationManager.getBestProvider(criteria, true);
if(provider == null){
provider = LocationManager.NETWORK_PROVIDER;
}
locationManager.requestLocationUpdates(provider, 60000, 5, this);
我的 onLocationChanged 监听器
@Override
public void onLocationChanged(Location location) {
Logging logger = new Logging();
logger.append("V", className, "onLocationChanged(Fine)", "Accuracy: " + location.getAccuracy());
try {
userLat = Double.toString(location.getLatitude());
userLong = Double.toString(location.getLongitude());
int mLat = (int) (location.getLatitude() * 1000000);
int mLng = (int) (location.getLongitude() * 1000000);
userLocation = new GeoPoint(mLat, mLng);
if (!initialFix && mapSettingShowLoc) {
showUserLocation(userLocation);
initialFix = true;
}
if (mapSettingShowLoc) {
showUserLocation(userLocation);
}
} catch (Exception e) {
logger.append("E", className, "onLocationChanged", "Exception: " + e);
}
}
在我onResume
注册再次收听,因为我可以从地图开始一个新的活动
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 1, this);
我究竟做错了什么?