Hi I am implementing two mapview in different activities they both works, the scenario is there is one large mapview which contains some projection points so when a point is clicked it should open up a new activity filled with some details. So my second activity is a scrollview layout that contains a small mapview at bottom which works fine
ISSUE: but when i press back button and goes back to previous mapview i get some warnings and that mapview doesnt load anymore i get a half of the map screen with white background
Main mapview: mapView show overlay details when clicked
so when i click on the balloon as shown in figure it opens up a new activity that also contains a mapview so when i press back button and gets back the main mapview(the one shown in figure above) cuts into half and i get these warnings:
02-22 14:39:39.806: WARN/System.err(7823): java.lang.IllegalStateException: Connection pool shut down.
02-22 14:39:39.806: WARN/System.err(7823): at org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:284)
02-22 14:39:39.806: WARN/System.err(7823): at org.apache.http.impl.conn.tsccm.ConnPoolByRoute$1.getPoolEntry(ConnPoolByRoute.java:238)
02-22 14:39:39.816: WARN/System.err(7823): at org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager$1.getConnection(ThreadSafeClientConnManager.java:175)
02-22 14:39:39.816: WARN/System.err(7823): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:325)
02-22 14:39:39.816: WARN/System.err(7823): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
02-22 14:39:39.826: WARN/System.err(7823): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
02-22 14:39:39.826: WARN/System.err(7823): at com.google.common.io.android.AndroidHttpClient.execute(Unknown Source)
02-22 14:39:39.826: WARN/System.err(7823): at com.google.common.io.android.GoogleHttpClient.executeWithoutRewriting(Unknown Source)
02-22 14:39:39.836: WARN/System.err(7823): at com.google.common.io.android.GoogleHttpClient.execute(Unknown Source)
02-22 14:39:39.836: WARN/System.err(7823): at com.google.common.io.android.GoogleHttpClient.execute(Unknown Source)
02-22 14:39:39.836: WARN/System.err(7823): at com.google.common.io.android.AndroidHttpConnectionFactory$AndroidGoogleHttpConnection.getResponse(Unknown Source)
02-22 14:39:39.836: WARN/System.err(7823): at com.google.common.io.android.AndroidHttpConnectionFactory$AndroidGoogleHttpConnection.openDataInputStream(Unknown Source)
02-22 14:39:39.846: WARN/System.err(7823): at com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(Unknown Source)
02-22 14:39:39.846: WARN/System.err(7823): at com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(Unknown Source)
02-22 14:39:39.846: WARN/System.err(7823): at java.lang.Thread.run(Thread.java:1102)
I found one post saying its not possible to implement two map view in an application, I found one solution here but didnt worked: How to use multiple MapActivities/MapV开发者_开发知识库iews per Android application/process
It says to start each mapview in different process as follows:
<activity android:name=".activity.directory.MapView1" android:process=":MapView1">
<activity android:name=".activity.directory.MapView2" android:process=":MapView2">
The above solution didnt worked for me, my code is as under:
MainMapView Class
public class CouponMapView extends MapActivity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.large_mapview);
mapView = (MapView) findViewById(R.id.mapview);
// mapView.setBuiltInZoomControls(true);
mapView.setStreetView(false);
mapView.setTraffic(false);
// layout = findViewById(R.id.)
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.mappointer);
ItemizedOverlay itemizedoverlay = new ItemizedOverlay(drawable, mapView, getParent());
OverlayItem overlayitem;
GeoPoint point = null;
double lat;
double lng;
try{
tempData = dataArray.gettempData();
for (int i = 0; i < this.totalLimit; i++) {
lat = Double.parseDouble(tempData.get(i).getLatitude());
lng = Double.parseDouble(tempData.get(i).getLongitude());
point = new GeoPoint((int) (lat * 1E6),(int) (lng * 1E6));
overlayitem = new OverlayItem(point, tempData.get(i).getId()+"", tempData.get(i).getInfo().getName());
itemizedoverlay.addOverlay(overlayitem);
itemizedoverlay.setBalloonBottomOffset(10);
mapOverlays.add(itemizedoverlay);
}
}catch(Exception e){
}
try{
final MapController mc = mapView.getController();
mc.animateTo(point);
mc.setZoom(16);
}catch(Exception e){
}
}
protected boolean isRouteDisplayed() {
// TfODO Auto-generated method stub
return false;
}
}
IM calling onTap method of this class to start a new activity
public class ItemizedOverlay extends BalloonItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> overlays = new ArrayList<OverlayItem>();
private Context context;
private Activity activity;
private int id;
public ItemizedOverlay(Drawable defaultMarker, MapView mapView, Activity activity) {
super(boundCenter(defaultMarker), mapView);
context = mapView.getContext();
this.activity = activity;
}
public void addOverlay(OverlayItem overlay) {
overlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return overlays.get(i);
}
@Override
public int size() {
return overlays.size();
}
@Override
protected boolean onBalloonTap(int index) {
Intent Details = new Intent(context, Tab.class);
Details.putExtra("Id", 1327);
context.startActivity(Details);
return true;
}
}
The third class is the details class that contains another mapview implementation and is a simple linearlayout but includes a map. I dont think there is anything wrong with the above code but there must be something i am missing in the first class to refresh its view, though i have tried view.requestlayout/view.invalidate but they didnt work either
I am implementing two mapview in different activities they both works, the scenario is there is one large mapview which contains some projection points so when a point is clicked it should open up a new activity filled with some details.
I would not recommend this. Use one MapActivity
with one MapView
and change your zoom/center to be where the point is clicked. Override onBackPressed()
, and if you are presently in "detail mode", change your zoom/center to be back where you were before. That way, you can do everything you want with only one MapView
, and this problem goes away.
So my second activity is a scrollview layout that contains a small mapview at bottom which works fine
Do not put a MapView
in a ScrollView
.
精彩评论