Eliminar superposición en el mapa

My application search and visual same overlays. But, in the next search the old overlay are not clear. I have to try to use map.getOverlays().clear(); but it remove also the overlay of MyLocationOverlay. There is a method for delete only same overlay?

preguntado el 28 de agosto de 11 a las 00:08

Remember to mark the answer if it resolved your issue. -

3 Respuestas

I know its a little too late, but since i came up with a solution that helped me, i thought of sharing it so that it helps programmers in the future..

@hooked82 : the problem with doing just


is that its a list. so when you remove one item from the list, every item to the right of this item, in the list, is shifted one place to the left, which will eventually mess up your positions making it really tedious to keep a track of them all over time.

During one of my projects, i faced the same issue. Since i was adding and removing overlays upon some updates, after a point of time, it was really difficult to keep a track of the overlay positions in the list.

Here is what i did as a work around for the problem, and so far there have been no issues.

Paso 1: create your custom Overlay Class

public class MyOverlay extends Overlay
    private String overlayUUID;

    public void draw(Canvas canvas, MapView mapView, boolean shadow)
          -- do what you need to do here -- 

    public String getOverlayUUID()
          return overlayUUID

Paso 2: in the MapClass where you handle the overlays. Please be sure that the mapOverlays list is a global list in the MapView class where you add all your mapOverlays

     List<Overlay> mapOverlays = mapView.getOverlays();

     public void removeChosenOverlay(String overlayUUID)
         for(int i=0; i<mapOverlays.size(); i++)
             String className = mapOverlays.get(i).getClass().getSimpleName();

                 MyOverlay myOverlay = (MyOverlay) mapOverlays.get(i);

                 if((myOverlay != null) && (myOverlay.getOverlayUUID.equals(overlayUUID)))

With the above method, one can uniquely identify each overlay with a UUID (in my case it was a string, but you can custom create your UUID's in any format you wish to) and remove the corresponding overlay item successfully from the list of overlays, without having to worry about their relative positions in the list.

I hope it helps others who face the same issues with uniquely identifying overlays.

Respondido el 14 de junio de 12 a las 20:06

and please mark the answer, if it helps anyone in the future.. Cheers.. !! - vivek86

When you add overlays to your map, you can add it to a certain position

overlays.add(position, overlay_object);

Then when you need to remove specific overlays, you can remove them in the same fashion


Respondido 28 ago 11, 09:08

you can do this with the help of the counter and another reference to the overlayItem to save old overlay which you want to remove in my case counter is current_overlay_counter and old_overlay_item get the reference for old overlay on the first call the counter is 0 so there is no overlay to remove

public void getcurrentPostion()
    GeoPoint gpoint=new GeoPoint((int)((current_location.getLatitude())*1E6),( (int)((current_location.getLongitude())*1E6)));
        OverlayItem overlayitem = new OverlayItem(gpoint, "Hola, Mundo!", "I'm in Mexico City!");       
        mapOverlays = map.getOverlays();  
            System.out.println("deleting overlay");


you need one more thing ,a method to remove the overlay in your ItemizedOverlay class implementation

this method takes the referece of the overlay you want to delete

public void removeOverlay(OverlayItem overlay){
          System.out.println("removeOverlay is called");

Respondido el 07 de diciembre de 12 a las 18:12

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.