Reputation: 2791
I am using the google map api with some markers. I also overrode the infoWindow as below to show custom text.
public void setUpMap() {
final GoogleMap map = mMapView.getMap();
map.clear();
map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
private View mHolder;
@Override
public View getInfoWindow(final Marker marker) {
Log.d("MAP", "Map clicked on marker = " + maker);
etc....
this works fine and I change the icon of each marker when clicked making them visually selected. However, I want to "unselect" all markers. The problem is that I don't know how to add a listener that gets triggered from outside of the markers.
In other words, my listener "getInfoWindow" gets trigger only when a marker is touched. I want the opposite. Some sort of listener that tells me that the user touched the map but not the markers.
Can this be done easily? Any pointers are greatly appreciated.
thx!
Upvotes: 4
Views: 2861
Reputation: 21
This is useful only when working with the Info Window. In my case, when the user clicks the marker, the corresponding Info window appears. So when the user clicks in the map outside the marker, the Info Window closes and that event is detected by the map.
// Detect when Marker's Info Window is closed
googleMap.setOnInfoWindowCloseListener(new GoogleMap.OnInfoWindowCloseListener() {
@Override
public void onInfoWindowClose(Marker marker) {
// Do whatever you want to do here...
}
});
Upvotes: 0
Reputation: 3627
Ok, I suppose that's really easy.
You have OnMarkerClickListener
and OnMapClickListener
.
So, in your case just register OnMapClickListener
and in onMapClick()
you can do what you need.
One more thing - when you add markers, store them in Arraylist
- then at any time you can do whatever is needed - even remove all markers from the map.
Upvotes: 5