tomchentw / react-google-maps

React.js Google Maps integration component
https://tomchentw.github.io/react-google-maps/
MIT License
4.63k stars 935 forks source link

How to remove markers from map ? #1060

Open mks1948 opened 4 years ago

mks1948 commented 4 years ago

Hello,

I have a big problem with remove markers in maps. I try to add marker instance and others. There is no information in the documentation on how to remove the markers. I try to use ref and remove according to by setMap(null) but this object is undefined. https://developers.google.com/maps/documentation/javascript/examples/marker-remove

const marker = new window.google.maps.Marker({
            position: event.latLng,
            map: props.map,
            title: "Dupa",
            visible: true
          });
         props.handleSavePoints(marker); // save in state all markers

removeMarker(){
 for (let i = 0; i < markers.length; i++) {
    markers[i].setMap(null);
  }
}

Even the simplest flag has no text markers from the map After a few day's i don't have the energy to resolve this problem.