2012-06-27 55 views
1

我在我的應用程序中有ItemizedOverlay兩個實例,其中一個用於CurrentLocation,另一個用於其他用途。我已將這兩個覆蓋圖添加到MapView如何從MapView中刪除特定的ItemizedOverlay?

我想更新CurrentLocation覆蓋當地圖的刷新按鈕傾斜。如果我這樣做,這意味着它也顯示了以前的當前位置,也顯示了新的位置。我如何刪除前一個?

但我還需要顯示另一個覆蓋。

我有子類的ItemizedOverlay

MyItemizedOverlay currentOverlay = new MyItemizedOverlay(pushPinDrawable); 
MyItemizedOverlay anotherOverlay = new MyItemizedOverlay(drawable); 

的刷新按鈕的代碼:

if (currentGeo != null) { 
    mapView.getOverlays().remove(currentOverlay); 
    mapVite(); 
    mapOverlays = mapView.getOverlays(); 
    myLocationOverlay = new OverlayItem(currentGeo, "My Location", mapTime.format(new Date(myLocationTime))); 
            // (currentGeo is the updated current geo point.) 
    currentOverlay.addOverlay(myLocationOverlay); 
    mapOverlays.add(currentOverlay); 
    mapController.animateTo(currentGeo); 
} else { 
    Toast.makeText(this, "Your Current Location is temporarily unavailable", Toast.LENGTH_LONG).show(); 
} 

任何想法?

回答

1

你應該有一些這樣的

public void onLocationChanged(Location location) { 
     if (mMyOverlay == null) { 
      mMyOverlay = new myOverlay(getResources().getDrawable(R.drawable.arrow), MyMap); 
      MyMap.getOverlays().add(mMyOverlay); 
     } else { 
      MyMap.getOverlays().remove(mMyOverlay); 
      MyMap.invalidate(); 
      mMyOverlay = new myOverlay(getResources().getDrawable(R.drawable.arrow), MyMap); 
      MyMap.getOverlays().add(mMyOverlay); 
     } 
     if (location != null) { 
      MyMap.invalidate(); 
      GeoPoint MyPos = new GeoPoint(microdegrees(location.getLatitude()), microdegrees(location.getLongitude())); 
      MyController.animateTo(MyPos); 
      mMyOverlay.addPoint(MyPos, "My position", "My position"); 
     } 
1

Berfore將在mapOverlays陣列CurrentOverlay,你一定能夠做這樣的事情,

if(mapOverlays.contains(itemizedOverlay)) 
{ 
    mapOverlays.remove(itemizedOverlay); 
} 
mapOverlays.add(itemizedOverlay); 
相關問題