Add multiple markers to Google Maps JavaScript

How to add multiple markers to google maps

In this blog post, we will learn how to add multiple markers to Google Maps with an example in asp.net web application. A marker identifies a location on a map. By default, a marker uses a standard image. Markers can display custom images/icons. Markers/Icons are objects of type Marker.

For example, by default they receive ‘click’ events, so you can add an event listener to bring up an info window displaying custom information. Also, you can allow users to move a marker on the map from one location to other by setting the marker’s draggable property to true. So in this article, I will demonstrate how to add multiple markers to google maps API v3 HTML. Find the source code below:-

Remove a Marker

To remove a marker from the map, call the setMap() method passing null as the argument.marker.setMap(null);

Note: The above method does not delete the marker. It simply removes the marker from the map. If instead, you wish to delete the marker, you should remove it from the map, and then set the marker itself to null.

If you wish to manage a set of markers, you should create an array to hold the markers. Using this array, you can then call setMap() on each marker in the array in turn when you need to remove the markers. You can delete the markers by removing them from the map and then setting the array’s length to 0, which removes all references to the markers. View Example

Did you find this post useful? I hope you liked this article. Please share with me your valuable suggestions and feedback.