////编辑前
我正在使用下面的代码在android地图上重绘一个标记,实际上它重绘了一个标记,但它并没有删除旧的,我试过了
mapView.invlaidate
但它并没有删除旧的。
这是 onLocationChanged 函数:
@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);
}
提前致谢。
/////编辑后
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);
}
非常感谢 imran khan 和 agarwal;我用你的答案来调试问题。