onInfoWindowClick 不起作用。但长按效果很好

onInfoWindowClick don't work. But Long click works fine

我已经在我的地图上添加了两个监听器:

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");
    }
});

并且根据 logcat 长按可以正常工作,但普通点击不行

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

你知道为什么会这样吗?

更新:实际上我只需要点击监听器,但它不起作用,所以我添加了长按监听器来测试它工作正常。

android-maps-utils 的新版本(在我的例子中是 1.3.1)需要使用 MarkerManager.Collection 来设置监听器。

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

新建

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);

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