You are only allowed to have a single MapView in a MapActivity
Posted
by
ProNeticas
on Stack Overflow
See other posts from Stack Overflow
or by ProNeticas
Published on 2011-03-07T05:08:06Z
Indexed on
2011/03/07
8:10 UTC
Read the original article
Hit count: 244
android
|android-maps
I have a function that shows a map page so I can get the user to choose their current location. But if you run this function twice it crashes the App with the Single MapView in a MapActivity error (i.e. opening that settings view again).
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);
}
So I have a button that shows this View and onClick="showMapSetterPage". But if you go back to the settings screen out of the map and click the button again I get this error:
03-06 20:55:54.091: ERROR/AndroidRuntime(28014): Caused by: java.lang.IllegalStateException: You are only allowed to have a single MapView in a MapActivity
How can I delete the MapView and recreate it?
© Stack Overflow or respective owner