How to get all markers in google-maps-react
How to get all markers in google-maps-react
I have the google-maps-react
in my project, but I don't know how to get all markers from the map?
google-maps-react
import React, Component from "react";
import Map, InfoWindow, Marker, GoogleApiWrapper from "google-maps-react";
import "../Body/Map.css";
import marker_icon from "../../img/marker_icon.png";
import hover_icon from "../../img/hover_icon.png";
import Grid, Row, Col from "react-bootstrap";
/*global google*/
export class MapContainer extends Component
constructor(props)
super(props);
this.state =
showingInfoWindow: false,
activeMarker: ,
selectedPlace:
;
onMarkerClick = (props, marker, e) =>
this.setState(
selectedPlace: props,
activeMarker: marker,
showingInfoWindow: true
);
;
onMapClicked = props =>
if (this.state.showingInfoWindow)
this.setState(
showingInfoWindow: false,
activeMarker: null
);
;
addMarker = (mapProps, map) =>
var marker = new google.maps.Marker(
position: ,
map: map
);
;
render()
const google = window.google;
const data = this.props.data;
return (
<div className="map-container">
<Map
google=this.props.google
className="map"
zoom=1
onClick=this.onMapClicked
onReady=this.addMarker
>
data.map(item => (
<Marker
key=item.id
title=item.name
name=item.name
position= lat: item.lat, lng: item.lng
onClick=this.onMarkerClick
/>
))
<InfoWindow
marker=this.state.activeMarker
visible=this.state.showingInfoWindow
>
<div className="info">
<h1>this.state.selectedPlace.name</h1>
</div>
</InfoWindow>
</Map>
</div>
);
export default GoogleApiWrapper(
apiKey: "AIzaSyDLgdweTnvhPnUE5yzdxcMeK876cFtMaSk"
)(MapContainer);
this.props.data
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What do you mean by "how to get all markers from the map"? You have all the marker data in the
this.props.data
array.– Tholle
1 min ago