Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add multiple ClusterManager to Google map

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.

like image 497
user2090251 Avatar asked Apr 29 '15 06:04

user2090251


People also ask

How many markers can Google Maps handle?

Answers. you can add 200 markers at a time but if you are using google service it will not response more than 10 or 20 at a time and if you have array of collection Lattitude and longitude just try to modify above code.


2 Answers

you can use MarkerManager 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));
like image 190
Zacharias Hadjikyprianou Avatar answered Sep 24 '22 06:09

Zacharias Hadjikyprianou


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)
  }
});
like image 28
chhabeg Avatar answered Sep 23 '22 06:09

chhabeg