Detect if user "deselected" on google map

I'm looking for a way to detect when a marker on a Google map is canceled. I have a sliding box where the pen is invisible until the user clicks on the marker, and I want to make it invisible again after the marker is “canceled”. I tried with marker.isInfoWindowShown() , but I could not get it to work.

+5
source share
3 answers

There is no event for the information window to disappear, but you can work with it using

 map.setOnMapClickListener(new OnMapClickListener() { ... }); 

and several other "events" that close the info window. If you use marker.remove() or marker.setVisible(false) , they also close the info window when you call the marker, which shows the info window.

You will need to save the markerShowingInfoWindow link (possibly from OnMarkerClickListener or InfoWindowAdapter ).

+10
source

I know that you have already chosen the answer, but the selected one does not do what you need.

I am also busy with an application that uses markers and has a view that switches when the user selects and deselects the marker.

This is a simple job.

  mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() { @Override public void onMapClick(LatLng latLng) { mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { @Override public boolean onMarkerClick(Marker marker) { //Code for on marker click goes here return false; } }); //Code for marker deselect goes here } }); 

This is the use of two click listeners. Thus, you can switch the visibility depending on what the user clicks.

0
source

This is only useful if the marker has an info window . When the information window appears when you click the marker and closes when you click outside the marker. You can find this event on the map.

 // Detect when Marker Info Window is closed googleMap.setOnInfoWindowCloseListener(new GoogleMap.OnInfoWindowCloseListener() { @Override public void onInfoWindowClose(Marker marker) { // Do whatever you want to do here... } }); 
0
source

Source: https://habr.com/ru/post/953665/


All Articles