title: Remove markers from map (Google Maps API v3)
body: <p>I'm developing an app with Google maps that should display several categories on a map. Now I would like to have the possibility to add markers from several categories and delete them as well if necessary.</p>
  <p>I've managed to figure out the whole thing. At least, almost... I'm having troubles with the removal of the markers of a category. I've created a live demo on jsfiddle to make this clear.
  So here's how I attempt to do this:</p>
  <h2>CODE</h2>
  <p>First I initialize the map, etc. (but that is not relevant here). Then I add the markers on the map:</p>
  <pre><code>for(i in markers){
      var marker = new google.maps.Marker({
          map: map,
          draggable: false,
          position: new google.maps.LatLng(markers[i].latitude, markers[i].longitude),
          visible: true,
          data: category
      });
      newMarkers.push(marker);
  }
  </code></pre>
  <p>As you can see I have 'data: category' in the object. This is something that's not google maps api, but it gives me no errors and gives me the possibility to search the array when I want to remove the markers. Here the removeMarker function:</p>
  <pre><code>function removeMarkers(category)
  {
      for(i in newMarkers) {
          if(newMarkers[i]['data'] == category){
              count ++;
              newMarkers[i].setMap(null); 
              newMarkers.splice(i, 1);
          }
      }
  }
  </code></pre>
  <p>It does remove markers, but not all of them...
  Does anyone have solution to my problem?</p>
  <h2><a href="http://jsfiddle.net/helenastandaert/GJUcy/" rel="nofollow noreferrer">LIVE DEMO</a></h2>
  <p>Thanks in advance,</p>
  <p>Helena S.</p>