0
可能重複:
GPS not update location after close and reopen app on android關於當前位置的android
我知道這個問題已經被問,但我的問題是。每次當我打開我的應用時,它顯示了最後的位置不是當前位置
我對當前位置的按鈕,我想,當我打開我的應用程序顯示它再經過在地圖上的當前位置,當我點擊按鈕
那麼它顯示當前的位置。
所以我的問題是,當我打開我的應用程序它顯示最後的位置,但是當我按然後它顯示當前位置。
代碼中的onCreate()
_locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
_locationListener = new CurrentLocationListener(this,this);
_locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1,1,_locationListener);
_currentGeoPoint = getKnownLocation();
_currentPosOverlay = new OverlayItem(_currentGeoPoint, "", "");
Log.d(" overlay", "overlaylast "+_currentGeoPoint);
// Toast.makeText(getBaseContext(), "overlay12333vvv "+_currentGeoPoint, Toast.LENGTH_SHORT).show();
_customOverlay.addOverlay(_currentPosOverlay);
_mapOverlays.add(_customOverlay);
代碼getKnownLocation()
// TODO Auto-generated method stub
Location lastLocation = _locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(lastLocation == null){
lastLocation = _locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
if(lastLocation != null){
GeoPoint gp = new GeoPoint((int)(lastLocation.getLatitude() * 1e6), (int)(lastLocation.getLongitude() * 1e6));
last_loc=gp;
return gp;
}else {
return _mapView.getMapCenter();
}
對於按鈕我稱爲getKnownLocation()