如何删除标记,并在Android地图改变位置时,再次重绘 [英] How to remove Marker and redraw it again when changing location on Android map

查看:383
本文介绍了如何删除标记,并在Android地图改变位置时,再次重绘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

////编辑之前

我使用的是下面的code重绘android上的地图标记,其实它重新绘制的标志,但它不会删除旧的,我试过

I am using the below code to redraw a Marker on android map, actually it redraw a marker but it doesn't remove the old one, I tried

mapView.invlaidate

但它没有删除旧的。

but it didn't remove the old one.

下面是onLocationChanged功能:

Here is the onLocationChanged function:

   @Override
 public void onLocationChanged(Location location) {
    // mapView.invalidate();

        //getCurrantPoint();
         OverlayItem currentOverlay = new OverlayItem(getCurrantPoint(),"Current Location","Here is my current location!!!");

            itemizedoverlay2.addOverlay(currentOverlay);
            mapOverlays.add(itemizedoverlay2);
            mapOverlays.remove(currentOverlay);
            Log.v("TAG", "Removeeeeeeeeeeeeeeeed");

         ///
         //mapOverlays.add(itemizedoverlay);
 }

在此先感谢。

Thanks in Advance.

/////编辑后

 if(itemizedoverlay2!=null)
     {
         mapOverlays.remove(itemizedoverlay2);

         itemizedoverlay2 = new HelloItemizedOverlay(drawable2, cntxt);
         OverlayItem currentOverlay = new OverlayItem(getCurrantPoint(),"Current Location","Here is my current location!!!");
         itemizedoverlay2.addOverlay(currentOverlay);

         mapOverlays.add(itemizedoverlay2);
     }
     else
     {
            itemizedoverlay2 = new HelloItemizedOverlay(drawable2, cntxt);

            OverlayItem currentOverlay = new OverlayItem(getCurrantPoint(),"Current Location","Here is my current location!!!");
            itemizedoverlay2.addOverlay(currentOverlay);
            mapOverlays.add(itemizedoverlay2);

     }

非常感谢伊姆兰汗和阿加瓦尔;我用你的答案来调试问题。

Big thanks to imran khan and agarwal; I used your answers to debug the problem.

推荐答案

试试这个:

OverlayItem currentOverlay = new OverlayItem(getCurrantPoint(),"Current Location","Here is my current location!!!");
itemizedoverlay2.addOverlayItem(currentOverlay);
mapOverlays.getOverlays().add(itemizedoverlay2);
mapOverlays.getOverlays().remove(itemizedoverlay2);
mapOverlays.invalidate();
Log.v("TAG", "Removeeeeeeeeeeeeeeeed");

// mapOverlays是你的MapView对象进行和itemizedoverlay2是你LocationOverlay

//mapOverlays is your mapView obejct and itemizedoverlay2 is your LocationOverlay

删除LocationOverlay即itemizedoverlay2而不是OverlayItem

这篇关于如何删除标记,并在Android地图改变位置时,再次重绘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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