[英]How to to make 2 MapView on one Activity?
是否可以在一個Activity上制作2個MapView?
如果是這樣,怎么做呢?
我已經嘗試過,但是沒有運氣。
提前致謝。
簡短的答案是否定的 。
目前,Android每個MapActivity僅支持一個MapView。
是的 ,我將這段代碼用於兩種不同的地圖----- 1.獲取gps位置----- 2.通過地區/城市/國家/地區名稱搜索時獲取某些位置。 代碼是
public void mapDisplay(double lat, double lng, int arg){
if(arg == 1){
mapView = (MapView)findViewById(R.id.map_view);
}
else if (arg ==2 ){
mapView = (MapView)findViewById(R.id.map_view2);
}
mapView.setBuiltInZoomControls(true);
//mapView.setStreetView(true);
//mapView.setTraffic(true);
//mapView.setSatellite(true);
// to display the pin point
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
CustomItemizedOverlay itemizedOverlay = new CustomItemizedOverlay(drawable, this);
GeoPoint point = new GeoPoint((int) (lat * 1E6), (int)(lng * 1E6));
OverlayItem overlayitem = new OverlayItem(point, "", "");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
mapView.getController().setZoom(18);
mapView.getController().setCenter(point);
mapView.getController().animateTo(point);
mapView.invalidate();
}
注意:調用此方法之前,請確保已設置ContentViews,然后
內部參數
在這里用來表示要調用哪個mapView。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.