Nikita Kalugin
Nikita Kalugin

Reputation: 742

onInfoWindowClick don't work. But Long click works fine

I've added two listeners to my map:

mGoogleMap.setOnInfoWindowLongClickListener(new GoogleMap.OnInfoWindowLongClickListener() {
    @Override
    public void onInfoWindowLongClick(Marker marker) {
        Log.d(TAG, marker.getTitle() + " Long click");
    }
});

mGoogleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
    @Override
    public void onInfoWindowClick(Marker marker) {
        Log.d(TAG, marker.getTitle() + " Just a simple click");
    }
});

And according to logcat long click works fine, but common click don't

2020-05-24 22:49:51.838 7940-7940/com.edwin.findme D/UserListFragment: test Long click
2020-05-24 22:49:53.309 7940-7940/com.edwin.findme D/UserListFragment: test Long click

Do you have any idea why is this happening?

UPD: Actually I need only click listener, but it's not working so I've added long click listener to test and it works fine.

Upvotes: 0

Views: 466

Answers (1)

Nikita Kalugin
Nikita Kalugin

Reputation: 742

New versions of android-maps-utils (1.3.1 in my case) requires to use MarkerManager.Collection to set a listener.

Source: https://github.com/googlemaps/android-maps-utils#adding-a-custom-info-window

New

CustomInfoWindowAdapter adapter = // ...
OnInfoWindowClickListener listener = // ...

// Create a new Collection from a MarkerManager
MarkerManager markerManager = // ...
MarkerManager.Collection collection = markerManager.newCollection();

// Set InfoWindowAdapter and OnInfoWindowClickListener
collection.setInfoWindowAdapter(adapter);
collection.setOnInfoWindowClickListener(listener);

// Alternatively, if you are using clustering
ClusterManager<ClusterItem> clusterManager = // ...
MarkerManager.Collection markerCollection = markerCollection.setInfoWindowAdapter(adapter);
markerCollection.setOnInfoWindowClickListener(listener);

Old

CustomInfoWindowAdapter adapter = // ...
OnInfoWindowClickListener listener = // ...
googleMap.setInfoWindowAdapter(adapter);
googleMap.setOnInfoWindowClickListener(listener);

Upvotes: 2

Related Questions