ユーザーが現在の場所を選択できるように、地図ページを表示する機能があります。ただし、この関数を 2 回実行すると、MapActivity エラー (つまり、その設定ビューを再度開く) で単一の MapView を使用してアプリがクラッシュします。
public void showMapSetterPage(View v) {
Log.i(DEBUG_TAG, "Settings screen, set map center launched");
// Set which view object we fired off from
set_pv(v);
// Show Map Settings Screen
setContentView(R.layout.set_map_center);
// Initiate the center point map
if (mapView == null) {
mapView = (MapView) findViewById(R.id.mapview);
}
mapView.setLongClickable(true);
mapView.setStreetView(true);
mapView.setBuiltInZoomControls(false);
mapView.setSatellite(false);
mapController = mapView.getController();
mapController.setZoom(18);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = lm
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
int lat = (int) (location.getLatitude() * 1E6);
int lng = (int) (location.getLongitude() * 1E6);
Log.i(DEBUG_TAG, "The LAT and LONG is: " + lat + " == " + lng);
point = new GeoPoint(lat, lng);
// mapController.setCenter(point);
mapController.animateTo(point);
}
したがって、このビューと onClick="showMapSetterPage" を表示するボタンがあります。しかし、マップから設定画面に戻ってボタンをもう一度クリックすると、次のエラーが表示されます。
03-06 20:55:54.091: エラー/AndroidRuntime(28014): 原因: java.lang.IllegalStateException: MapActivity に許可されている MapView は 1 つだけです
MapView を削除して再作成するにはどうすればよいですか?