1
在我的地圖應用程序,我不似乎越來越位置更新,我上了車,並開始駕駛周圍,但我的位置標記從未改變在地圖上,甚至給了我一個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);
我做錯了什麼?
那麼你是否獲得位置更新呢?另外,我注意到,在第一個模塊中,您要求在2米處每60秒進行一次「粗略」更新(網絡),而在onresume中,您需要2秒和1米的GPS。出於經驗,我會特別問你想要什麼GPS,NETWORK或兩者,而不是把它留給系統(許多實現使用網絡時,他們應該使用GPS,反之亦然,這是取決於設備) – Idistic 2012-07-08 02:20:05
當你同時啓動Google地圖?這工作正常嗎? – PVS 2012-07-08 02:50:11
是的谷歌地圖工作正常,我幾乎每天都在使用它。我唯一一次獲得位置更改的時間是該活動的第一次運行。如果我導航到一個新的活動,在我的'onPause'中調用'removeUpdates',那麼當你看到我的簡歷是如何的時候,我不會再接到另一個'onLocationChange'調用 – tyczj 2012-07-08 03:15:53