add multiple ClusterManager to Google map

2019-04-06 10:34发布

I am trying to use two ClusterManager for Google Map , But I am able to add only one clustermanager and it's item click event,

googleMap.setOnMarkerClickListener(mClusterManager);

and

mClusterManager.setOnClusterItemClickListener(new OnClusterItemClickListener<Person>() {

    @Override
    public boolean onClusterItemClick(Person item) {
        Log.v("Cluster Click", "Item Click:"+item.getName());
        return true;
    }
});

How can I add one more clustermanager to googlemap?

Thanks in advance.

2条回答
闹够了就滚
2楼-- · 2019-04-06 10:52

you can use MarketManager like this:

MarkerManager markerManager = new MarkerManager(mMap);

mClusterManager1 = new ClusterManager<>(getContext(), mMap,markerManager);
mClusterManager2 = new ClusterManager<>(getContext(), mMap,markerManager);

mMap.setOnMarkerClickListener(markerManager);

mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
        @Override
        public void onCameraChange(CameraPosition cameraPosition) {
            mClusterManager1.onCameraChange(cameraPosition);
            mClusterManager2.onCameraChange(cameraPosition);
        }
    });


mClusterManager1.setRenderer(myClusterRenderer1 = new MyClusterRenderer(getContext(), mMap, mClusterManager1));
mClusterManager2.setRenderer(myClusterRenderer2 = new MyClusterRenderer(getContext(), mMap, mClusterManager2));
查看更多
Anthone
3楼-- · 2019-04-06 11:16

yes, delegate the click listener through to both cluster managers.

map.setOnClickListener(new GoogleMap.OnMarkerClickListener() {
  boolean onMarkerClick(Marker m) {
    clusterManager1.onMarkerClick(m)
    clusterManager2.onMarkerClick(m)
  }
});
查看更多
登录 后发表回答