启动多个活动地图 [英] Starting Multiple map activities

查看:113
本文介绍了启动多个活动地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实施不同的活动,他们都Works的图形页面,该方案是有其中包含了一些投影点,所以当一个点被点击它应该会充满了一些细节的新活动一个大的图形页面。所以,我的第二个活动是包含一个小型图形页面底部滚动型布局,正常工作

问题但是当我preSS后退按钮返回到previous的MapView我得到一些警告和MapView的犯规负荷了,我得到了地图的一半屏幕采用白色背景

主要图形页面:图形页面显示叠加的细节时,点击

所以,当我如图气球点击它开辟了一个新的活动,还包含一个图形页面,所以当我preSS后退按钮和回来的主要图形页面(如上图所示)切入一半,我得到这些警告:

  02-22 14:39:39.806:WARN / System.err的(7823):java.lang.IllegalStateException:连接池关闭。
02-22 14:39:39.806:WARN / System.err的(7823):在org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:284)
02-22 14:39:39.806:WARN / System.err的(7823):在org.apache.http.impl.conn.tsccm.ConnPoolByRoute $ 1.getPoolEntry(ConnPoolByRoute.java:238)
02-22 14:39:39.816:WARN / System.err的(7823):在org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager$1.getConnection(ThreadSafeClientConnManager.java:175)
02-22 14:39:39.816:WARN / System.err的(7823):在org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:325)
02-22 14:39:39.816:WARN / System.err的(7823):在org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
02-22 14:39:39.826:WARN / System.err的(7823):在org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
02-22 14:39:39.826:WARN / System.err的(7823):在com.google.common.io.android.AndroidHttpClient.execute(来源不明)
02-22 14:39:39.826:WARN / System.err的(7823):在com.google.common.io.android.GoogleHttpClient.executeWithoutRewriting(来源不明)
02-22 14:39:39.836:WARN / System.err的(7823):在com.google.common.io.android.GoogleHttpClient.execute(来源不明)
02-22 14:39:39.836:WARN / System.err的(7823):在com.google.common.io.android.GoogleHttpClient.execute(来源不明)
02-22 14:39:39.836:WARN / System.err的(7823):在com.google.common.io.android.AndroidHttpConnectionFactory$AndroidGoogleHttpConnection.getResponse(Unknown资源)
02-22 14:39:39.836:WARN / System.err的(7823):在com.google.common.io.android.AndroidHttpConnectionFactory$AndroidGoogleHttpConnection.openDataInputStream(Unknown资源)
02-22 14:39:39.846:WARN / System.err的(7823):在com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(来源不明)
02-22 14:39:39.846:WARN / System.err的(7823):在com.google.googlenav.datarequest.DataRequestDispatcher $ DispatcherServer.run(来源不明)
02-22 14:39:39.846:WARN / System.err的(7823):在java.lang.Thread.run(Thread.java:1102)

我发现一个帖子说其不可能实现在应用程序两种地图的看法,我发现了一个解决方案,但在这里工作剪掉:
<一href=\"http://stackoverflow.com/questions/3379575/how-to-use-multiple-mapactivities-mapviews-per-android-application-process\">How使用多个MapActivities /每个Android应用程序/流程MapViews

它说,开始在不同的进程中的每个图形页面如下:

 &LT;活动机器人:activity.directory.MapView1NAME =机器人:工艺=:MapView1&GT;
&LT;活动机器人:activity.directory.MapView2NAME =机器人:工艺=:MapView2&GT;

以上解决方案剪掉工作对我来说,我的code是为下:

MainMapView类

 公共类CouponMapView扩展MapActivity {    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.large_mapview);
        图形页面=(图形页面)findViewById(R.id.mapview);
       // mapView.setBuiltInZoomControls(真);
        mapView.setStreetView(假);
        mapView.setTraffic(假);
       //布局= findViewById(R.id。)        清单&LT;&叠加GT; mapOverlays =调用MapView.getOverlays();
        可绘制可绘制= this.getResources()getDrawable(R.drawable.mappointer)。
        ItemizedOverlay itemizedoverlay =新ItemizedOverlay(绘制,MapView类,的getParent());
        OverlayItem overlayitem;
        的GeoPoint点= NULL;
        双纬度;
        双LNG;        尝试{
            TempData的= dataArray.gettempData();            的for(int i = 0; I&LT; this.totalLimit;我++){
                纬度= Double.parseDouble(tempData.get(ⅰ).getLatitude());
                经度= Double.parseDouble(tempData.get(ⅰ).getLongitude());                点=新的GeoPoint((INT)(LAT * 1E6),(INT)(LNG * 1E6));                overlayitem =新OverlayItem(点,tempData.get(ⅰ).getId()+,tempData.get(ⅰ).getInfo()的getName());
                itemizedoverlay.addOverlay(overlayitem);
                itemizedoverlay.setBalloonBottomOffset(10);
                mapOverlays.add(itemizedoverlay);            }
        }赶上(例外五){        }
        尝试{
            最后MapController MC = mapView.getController();
            mc.animateTo(点);
            mc.setZoom(16);
        }赶上(例外五){        }
    }
    保护布尔isRouteDisplayed(){
        // TfODO自动生成方法存根
        返回false;
    }
}

即时调用这个类的方法的onTap启动一个新的活动

 公共类ItemizedOverlay扩展BalloonItemizedOverlay&LT; OverlayItem&GT; {
    私人的ArrayList&LT; OverlayItem&GT;覆盖=新的ArrayList&LT; OverlayItem&GT;();
    私人上下文的背景下;
    私人活动活动;
    私人诠释身份证;    公共ItemizedOverlay(可绘制defaultMarker,MapView类MapView类,活动活动){
        超(boundCenter(defaultMarker),图形页面);
        上下文= mapView.getContext();
        this.activity =活动;
    }    公共无效addOverlay(OverlayItem叠加){
        overlays.add(覆盖);
        填充();
    }    @覆盖
    保护OverlayItem createItem中(int i)以{
        返回overlays.get(ⅰ);
    }    @覆盖
    公众诠释大小(){
        返回overlays.size();
    }    @覆盖
    保护布尔onBalloonTap(INT指数){
        意图详情=新意图(背景下,Tab.class);
        Details.putExtra(ID,1327);
        context.startActivity(详细信息);
        返回true;
    }
}

第三类是包含另一个MapView的实施,是一个简单的LinearLayout,但包括地图的细节类。我不觉得有什么不妥上述code,但一定有什么东西我在第一堂课缺少刷新其观点,虽然我已经试过view.requestlayout / view.invalidate但他们没有工作,要么


解决方案

  

我采取不同的活动,他们都Works的图形页面,该方案是有其中包含了一些投影点,所以当点击一个点就应该打开了充满一些细节的新活动一个大的图形页面。


我不建议这一点。使用一个 MapActivity 一个图形页面,改变你的缩放/中心是被点击的地步。覆盖 onBack pressed(),如果你是presently中的详细模式,改变你的缩放/中心能回到你在哪里了。这样,你可以做你想做只有一个图形页面的一切,而这个问题就会消失。


  

所以我的第二个活动是包含一个小型图形页面底部滚动型布局,正常工作


不要把图形页面滚动型

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/MapViews 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.

这篇关于启动多个活动地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆