How to remove all markers with Google Maps API v3 and JavaScript?

Spread the love

Sometimes, we want to remove all markers with Google Maps API v3 and JavaScript.

In this article, we’ll look at how to remove all markers with Google Maps API v3 and JavaScript.

How to remove all markers with Google Maps API v3 and JavaScript?

To remove all markers with Google Maps API v3 and JavaScript, we can use a for loop.

For instance, we write

for (const marker of markersArray) {
  marker.setMap(null);
}

to loop through the markersArray with a for-of loop.

In it, we call marker.setMap with null to remove each marker.

Conclusion

To remove all markers with Google Maps API v3 and JavaScript, we can use a for loop.

Leave a Reply

Your email address will not be published.