search

Home  >  Q&A  >  body text

Cluster click event handling with Angular 11 and Google Maps API

I am working on an angular 16 project.

this.markerCluster = new MarkerClusterer({map:this.map, markers: this.markers, renderer, onClusterClick:this.listCluster.bind(this),
                });
listCluster(cluster){
        let markers = cluster.getMarkersList();
        console.log(markers);
    }

I need to get the list of markers present in a specific cluster. I've tried getMarkers() and getMarkersList() but neither works.

P粉798343415P粉798343415529 days ago655

reply all(1)I'll reply

  • P粉464082061

    P粉4640820612023-09-17 19:02:34

    You are trying to use a method to get markers in a cluster, but the method you need depends on the specific version of the MarkerClusterer library you are using.

    In newer versions of the @google/markerclusterer library (since v3), you can use the getMarkers() method to retrieve markers within a cluster:

    listCluster(cluster){
      let markers = cluster.getMarkers();
      console.log(markers);
    }

    reply
    0
  • Cancelreply