How can I get the Google Maps Marker object instances from a map?
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 ;)
Most helpful comment
I may have a similar question. Did you figure it out perhaps?