【发布时间】:2011-09-28 15:51:55
【问题描述】:
可能重复:
GPS not update location after close and reopen app on 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() 的按钮
【问题讨论】: