tomchentw / react-google-maps

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

How to remove markers from map ? #1060

Open mks1948 opened 3 years ago

mks1948 commented 3 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.