点击后退按钮后谷歌地图重绘

时间:2012-03-26 15:51:05

标签: android redraw

我的应用程序中有一个带有不同标记的谷歌地图。当我点击标记(onTap())时,会出现一个新的详细信息窗口,并显示有关特定位置的一些信息。我的问题是,当我点击后,整个地图重绘。我可以看到它,因为每次打开infowindow并点击后退按钮时,标记的阴影会变暗。此外,它总是缩放回我当前的位置( - >触发整个onResume()方法。)

我怎样才能避免每次重绘地图?

重叠项目类:

@Override
public boolean onTap(int index) {
    OverlayItem item = mOverlays.get(index);
    Item item = map.get(item);

    Intent intent = new Intent();
    intent.setClass(mContext, SomeExampleClass.class);
    mContext.startActivity(intent);

    return true;
}

地图类:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.map);

    mapView = (MapView) findViewById(R.id.mainmap);
    mapView.invalidate();

    mapView.setBuiltInZoomControls(true);   

    dbZugriff = new DatabaseAccess(this);

    mylocationoverlay = new MyLocationOverlay(this, mapView);
    mc = mapView.getController();

}


@Override
protected void onResume() {

    super.onResume();

    mylocationoverlay.enableMyLocation();


    mapView.getOverlays().add(mylocationoverlay);
    mylocationoverlay.runOnFirstFix(new Runnable(){

        @Override
        public void run() {
            GeoPoint myLocation = mylocationoverlay.getMyLocation();
            mc.animateTo(myLocation);
            mc.setZoom(16);

            mapView.postInvalidate();
        }

    });

      SharedPreferences prefs = getSharedPreferences("prefs",Context.MODE_PRIVATE);

      SpecialitiesSelection specialitiesSelection = SpecialitiesSelection.loadFromPreferences(prefs, "");

    Cursor resultat = dbZugriff.createCursor(specialitiesSelection); 

    mapOverlays = mapView.getOverlays(); 

    List<Item> list = new ArrayList<Item>();

    if (resultat.moveToFirst()){
        do{

        Item daten = Item.createFromCursor(resultat);
        list.add(daten);

        }
        while(resultat.moveToNext());            
    }

Drawable drawable = this.getResources().getDrawable(R.drawable.ic_launcher);
itemizedoverlay = new  ItemOverlay(drawable,this,list);

    mapOverlays.add(itemizedoverlay);

}

1 个答案:

答案 0 :(得分:2)

每次从SomeExampleClass按BACK时,都会调用onResume()。在onResume(),你正在做你不想发生的一切。因此,请将此代码移到其他位置(例如onCreate())。

相关问题