title: Removing group of markers Google maps API v3
body: <p>I want to view and remove markers on map depending on user click over location type..</p>
  
  <p>I am using this code to remove markers</p>
  
  <p>1- Define markersArray as global array</p>
  
  <pre><code> var markersArray =new Array();
  </code></pre>
  
  <p>2- Define clearOverlays function</p>
  
  <pre><code>function clearOverlays() {
  
  
     if ( markersArray &amp;&amp;  markersArray.length) {
  
  
      google.maps.Map.prototype.clearOverlays = function() {
  
          for (var i = 0; i &lt;  markersArray.length; i++ ) {
  
              markersArray[i].setMap(null);
          }
      } 
  
       markersArray = [];
       markersArray = new Array();
       markersArray.length = 0;
    }
  
  }
  </code></pre>
  
  <p>3- I call the function when I want to remove the markers</p>
  
  <p><strong>The problem</strong> is that: Nothing is removed from the map!</p>
  
  <p>I wonder to know why!</p>
  
  <p><strong>Edit:</strong> Here where I add markers and push them into markersArray</p>
  
  <pre><code>  downloadUrl("getPlacesForType/"+markerType+"/"+lang, function(data) {
  
  
                  var xml = data.responseXML;
  
                  var myMarkersArray = xml.documentElement.getElementsByTagName("marker");
  
  
                  for (var i = 0; i &lt; myMarkersArray.length; i++) {
  
                      var name = myMarkersArray[i].getAttribute("name");
                      var version = myMarkersArray[i].getAttribute("version");
                      var description = myMarkersArray[i].getAttribute("description");
                      var type = myMarkersArray[i].getAttribute("type");
                      var point = new google.maps.LatLng(
                          parseFloat(myMarkersArray[i].getAttribute("lat")),
                          parseFloat(myMarkersArray[i].getAttribute("lng")));
                      var html = "&lt;b&gt;" + name + "&lt;/b&gt; &lt;br/&gt;" + description;
                      var icon = customIcons[type] || {};
  
                      var marker = new google.maps.Marker({
                          map: map,
                          position: point ,
                          icon: icon.icon,
                          shadow: icon.shadow
                      });
                      markersArray.push(marker);
                      bindInfoWindow(marker, map, infoWindow, html);
                  } 
              }); 
  </code></pre>