Search code examples
osmdroid

how to do that when i click on the map, the marker disappeared?


I use asmdroid 4.2 and bonuspack 4.5.

my code add marker:

       Marker startMarker = new Marker(mapView);
        startMarker.setPosition(new GeoPoint(locationA,locationB));
        startMarker.setIcon(getResources().getDrawable(drawable)); 
        startMarker.setTitle("jkdfghspdifj");
        startMarker.setAnchor(Marker.ANCHOR_CENTER, 1.0f);
        MarkerInfoWindow infoWindow = new  MyInfoWindow(R.layout.bonuspack_bubble, 
                mapView,title);
        startMarker.setInfoWindow(infoWindow);


 mapView.getOverlays().add(startMarker);

 mapView.zoomToBoundingBox(boundingBox);

 mapView.invalidate(); 

everything works fine :)

I click on the marker and displayed popup window. and how to do that when you click on the card itself, the marker disappeared? (at the moment it disappears unless again click on it)


Solution

  • To close all open popups when tapping anywhere on the map, follow the Tutorial 5, Chapter 16. Handling Map events

    To have an open popup that closes when you are opening the popup on an other marker, a simple solution is to share the same infoWindow object between all your markers.

    Or call "InfoWindow.closeAllInfoWindowsOn(map);" in onOpen.