带有InfoWindowAdapter的ClusterManager不起作用

时间:2017-10-29 13:05:34

标签: android google-maps google-maps-markers

我正在使用google's android Map Utils,以下是我用来尝试生成信息窗口的代码。

    /*
     * Set the Google Marker Cluster Manager.
     */
    mClusterManager = new ClusterManager<>(this, mGoogleMap);

    mGoogleMap.setOnCameraIdleListener(mClusterManager);
    mGoogleMap.setInfoWindowAdapter(mClusterManager.getMarkerManager());
    mGoogleMap.setOnMarkerClickListener(mClusterManager.getMarkerManager());
    mGoogleMap.setOnInfoWindowClickListener(mClusterManager);

    mGoogleMap.setInfoWindowAdapter(mPlaceInfoWindowAdapter);

    mGoogleMap.setOnMarkerClickListener(mClusterManager);

    GoogleMap.InfoWindowAdapter infoWindowAdapter = new GoogleMap.InfoWindowAdapter()
    {
        @Override
        public View getInfoWindow(Marker marker)
        {
            Toast.makeText(MainActivity.this, "getInfoWIndow", Toast.LENGTH_SHORT).show();
            return null;
        }

        @Override
        public View getInfoContents(Marker marker)
        {
            View v = LayoutInflater.from(MainActivity.this).inflate(R.layout.map_infowindow_layout, null);
            Toast.makeText(MainActivity.this, "getInfoContents", Toast.LENGTH_SHORT).show();
            return v;
        }
    };

    mClusterManager.getMarkerCollection().setOnInfoWindowAdapter(infoWindowAdapter);

    mClusterManager.getClusterMarkerCollection().setOnInfoWindowAdapter(infoWindowAdapter);

    mClusterManager.setOnClusterClickListener(new ClusterManager.OnClusterClickListener<MapMarker>()
    {
        @Override
        public boolean onClusterClick(Cluster<MapMarker> cluster)
        {
            Toast.makeText(MainActivity.this, "cluster click", Toast.LENGTH_SHORT).show();
            return false;
        }
    });

    mClusterManager.setOnClusterItemClickListener(new ClusterManager.OnClusterItemClickListener<MapMarker>()
    {
        @Override
        public boolean onClusterItemClick(MapMarker mapMarker)
        {
            Toast.makeText(MainActivity.this, "cluster item click", Toast.LENGTH_SHORT).show();
            return false;
        }
    });

下面是单击地图上标记时的结果图像。 从不调用InfoWindowAdapter的方法。

Code result

我也尝试设置mGoogleMap.setOnMarkerClickListener(mClusterManager),但这也不起作用。我做错了什么,或者这是谷歌代码的错误吗?

1 个答案:

答案 0 :(得分:0)

我通过从false方法返回onClusterItemClick来解决此问题。如果设置为true,则信息窗口不会显示。