Google-maps-react: How can I get all marker after it render?

Created on 21 Apr 2018  路  3Comments  路  Source: fullstackreact/google-maps-react

How can I get the Google Maps Marker object instances from a map?

Most helpful comment

I may have a similar question. Did you figure it out perhaps?

All 3 comments

I may have a similar question. Did you figure it out perhaps?

I tried this way to find the all markers, but I could not use Marker Component.
Instead I create marker myself.
I didn't find the way to use Marker Component and get all markers at the same time.

Here is the code.

<Map
  google={google}
  markers={markers}
  initialCenter={position}
  // 鈫撯啌 use onReady
  onReady={this.onReady.bind(this)} />
onReady(mapProps, map) {
  const markerList= [];

  markers.forEach(marker => {
    const {anchorSize, scaledSize} = marker.icon;

    // 鈫撯啌 create Marker myself
    const item = new google.maps.Marker({
      position: marker.position,
      map: map,
      name: marker.name,
      icon: {
        url: marker.icon.url,
        anchor: new google.maps.Point(anchorSize.width, anchorSize.height),
        scaledSize: new google.maps.Size(scaledSize.width, scaledSize.height)
      }
    });
    item.addListener('click', this.onMarkerClick.bind(this));
    markerList.push(item);
  }, this);


  this.setState({
    markerList: markerList
  });
}

If you add more options for marker, plz look at this document.

I hope you could fix this issue ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

EmmaU25 picture EmmaU25  路  3Comments

rullymartanto picture rullymartanto  路  5Comments

mruoss picture mruoss  路  5Comments

t1a2l picture t1a2l  路  5Comments

lishi500 picture lishi500  路  4Comments