Mr Pablo
Mr Pablo

Reputation: 4187

Detect when a user clicks off a marker

So I am using Google Maps in my app and I am customising the onMarkerClick event to show a button.

Is it possible to detect when a user clicks "off" the marker e.g. tapping the map itself, or scrolling maybe? Anything that means the marker loses focus.

Upvotes: 1

Views: 891

Answers (2)

Cesar
Cesar

Reputation: 21

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. This is useful only when the marker has an Info Window.

// 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: 1

N Dorigatti
N Dorigatti

Reputation: 3540

there are some listener on the map you can use: https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap

you can see:

interface GoogleMap.OnCameraChangeListener Defines signatures for methods that are called when the camera changes position.

interface GoogleMap.OnMapClickListener Callback interface for when the user taps on the map.

interface GoogleMap.OnMapLongClickListener Callback interface for when the user long presses on the map.

interface GoogleMap.OnMyLocationButtonClickListener Callback interface for when the My Location button is clicked.

All of these can help you. I usually use only on mapClickListener for these kind of use cases

Upvotes: 3

Related Questions