我面临一个奇怪的问题。当我使用 WIFI 时,我的应用程序在地图上显示当前位置,但是当我关闭 WIFI 以使用 GPS 进行检查时,它仍然显示当前位置但没有显示地图。它使地图消失并显示当前位置。有人可以告诉我为什么会这样吗?这是我的代码:
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapController = mapView.getController();
me = new MyLocationOverlay(this, mapView);
me.enableMyLocation();
mapView.getOverlays().add(me);
mapController.setZoom(10);
mapView.invalidate();
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// locationManager.requestLocationUpdates(
// LocationManager.NETWORK_PROVIDER, 0, 0, new GeoUpdateHandler());
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0, new GeoUpdateHandler());
}
@Override
protected void onDestroy() {
me.disableMyLocation();
super.onDestroy();
}
@Override
protected void onPause() {
super.onPause();
me.disableMyLocation();
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
public class GeoUpdateHandler implements LocationListener {
// @Override
public void onLocationChanged(Location location) {
int lat = (int) (location.getLatitude() * 1E6);
int lng = (int) (location.getLongitude() * 1E6);
GeoPoint point = new GeoPoint(lat, lng);
Toast.makeText(getApplicationContext(), "lat and lng"+lat+lng , Toast.LENGTH_SHORT).show();
mapController.setZoom(18);
mapController.animateTo(point); // mapController.setCenter(point);
mapView.invalidate();
}