VIGNESH
VIGNESH

Reputation: 2033

BalloonView in MapView not hidding

I have searched for a long time and have tried everything related to this but i was not successful . Any related answers are welcomed .

i have used the following code in my BalloonItemizedOverlay

protected void hideBalloon() 
    {
        if (balloonView != null) 
        {
            balloonView.setVisibility(View.GONE);
        }
    }


    private void hideOtherBalloons(List<Overlay> overlays) 
    {   
        for (Overlay overlay : overlays) 
        {
            if (overlay instanceof BalloonItemizedOverlay<?> && overlay != this) 
            {
                ((BalloonItemizedOverlay<?>) overlay).hideBalloon();
            }
        }
    }

and whenever i set the mapview , i call

mapView.getOverlays().clear();
mapView.invalidate();

but for the first time i tap on the markerpin , i get the balloonView correctly . When i go back to the list and come again to the same mapview with different marker values , i get the balloonView open and when i tap the markerpin again i get the right values but overlapped on the older BalloonView .

How to hide all the balloonView before setting new overlays to the mapView . i want to reuse the same mapView for different values from various places in the same Activity .

Upvotes: 0

Views: 48

Answers (2)

AndroidEnthusiastic
AndroidEnthusiastic

Reputation: 931

You just need to do a good google search.

Here's a thorough walkthrough:

https://github.com/jgilfelt/android-mapviewballoons

Upvotes: 0

user1644532
user1644532

Reputation:

I have done it as gven below and its working successfully. You have to edit this code according to your requirement:-

 public class CustomItemizedOverlay extends ItemizedOverlay<CustomOverlayItem>{

    private ArrayList<CustomOverlayItem> mOverlays = new ArrayList<CustomOverlayItem>();




    public void addDeleteMarker{

    CustomOverlayItem overlaySosItem;

    if(mOverlays.size()!=0){

    for(i=0;i<mOverlays.size();i++){

    //---------To remove (Edit index position according to your logic)----------
    mOverlays.remove(i);


    //---------To Add Overlay-----------

    GeoPoint geoPoint = new GeoPoint((int)(yourlatitude *1e6),(int)(yourlongitude*1e6));
    overlaySosItem = new CustomOverlayItem(geoPoint, "", "");

     mOverlays.add(overlaySosItem);
    }
    }
    }
    }

Upvotes: 1

Related Questions