在我的地图应用程序中,我似乎没有获得位置更新,我上了车并开始四处开车,但我的位置标记在地图上从未改变,甚至给了我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);
我做错了什么?
答案 0 :(得分:1)
我想通了,这是因为我有错过匹配的提供商