群集标记单击事件Android

时间:2015-12-28 07:12:44

标签: cluster-computing marker

我正在utils library中使用Google地图标记群集。单击群集时,不会调用以下onClusterClick方法。有Cluster click event吗?

 @Override
    public boolean onClusterClick(Cluster<MyItem> cluster)
    {        
        return true;
    }

3 个答案:

答案 0 :(得分:3)

您需要在此之前添加以下内容:

map.setOnMarkerClickListener(yourClusterManager);

答案 1 :(得分:2)

以下是如何实现您的要求,即点击群集或群集项目的方式。

mapSupportFragment.getMapAsync(new OnMapReadyCallback() {
    @Override
    public void onMapReady(GoogleMap googleMap) {

        mMap = googleMap; //(Here mMap is my GoogleMap object declared & was initialized).

        // Initialize the manager with the context and the map.
        mClusterManager = new ClusterManager<AppClusterItem>(MFragmentActivity.this, mMap);
        mClusterManager.setRenderer(new MyCustomRender(MFragmentActivity.this, mMap, mClusterManager)); 
        // Here which I used is my custom rendering class

        // Point the map's listeners at the listeners implemented by the cluster manager.
        mMap.setOnCameraChangeListener(mClusterManager);
        mMap.setOnMarkerClickListener(mClusterManager);

        mClusterManager.setOnClusterClickListener(new ClusterManager.OnClusterClickListener<AppClusterItem>() {
            @Override
            public boolean onClusterClick(Cluster<AppClusterItem> cluster) {

                Log.e("I clicked @ ", "Cluster which consumes whole list of ClusterItems");
                return false;
            }
        });

        mClusterManager.setOnClusterItemClickListener(new ClusterManager.OnClusterItemClickListener<AppClusterItem>() {
            @Override
            public boolean onClusterItemClick(AppClusterItem item) {
                Log.e("I clicked @ ", "Cluster Item");
                return false;
            }
        });
    }
});

此解决方案不允许您使用 GoogleMap.setOnMarkerClickListener 方法,然后使用you can read this answer

答案 2 :(得分:1)

麻省太晚了,但如果有人想知道: 只需在CkusterManger上设置OnClusterItemClcikListener:

        mClusterManager.setOnClusterItemClickListener(this);

然后让你的类实现ClusterManager.OnClusterItemClickListener

activity a implements ClusterManager.OnClusterItemClickListener .... 

然后最后打电话

 @Override
public boolean onClusterItemClick(ClusterItem clusterItem) {
    Toast.makeText(getActivity(), "clciked", Toast.LENGTH_SHORT).show();
    return true;
}