title: Google Maps API v3: Markers not being removed
body: <p>I'm creating a map that loads &amp; destroys markers based on both the bounding box and zoom level. I'm having a real problem getting markers to properly be removed, it seems to work sometimes for certain situations.</p>
  
  <p>I have an object that contains the marker info, which also contains the google maps marker object. My code detects if the market should be deleted based on the bounding box or zoom-level. I set the marker object to "setMap(null);" and using firebug I can see that its being set, I then remove the parent object entirely and the objects data length is updated properly.</p>
  
  <p>I output to the firebug console when a marker is supposedly deleted, seems to be working and I can see that the marker isn't being re-crated from the ajax call for markers on the boundingbox change.</p>
  
  <p>Yet if I zoom around the map I can sometimes see that the markers are being removed, if I zoom away then pan back holding the mouse down. Or sometimes the markers will all be removed if I zoomout the first time, but if I zoom in again then back out they are not removed.</p>
  
  <p>I must be doing something wrong with the logic of my code, I'm stumped.</p>
  
  <p>You can view the source of 
  <a href="http://www.trailforks.com/map/test.php?lat=49.352247&amp;lon=-123.202413" rel="noreferrer">http://www.trailforks.com/map/test.php?lat=49.352247&amp;lon=-123.202413</a>
  the JS is
  <a href="http://www.trailforks.com/map/includes/map.js" rel="noreferrer">http://www.trailforks.com/map/includes/map.js</a></p>
  
  <p>the code for deleting a marker is at the bottom</p>
  
  <pre><code>function clearMarkerMemory(mapItem, i) {
    google.maps.event.removeListener(mapItem.lis);    // remove stored listener
  
    mapper.data[i].obj.setMap(null); // remove marker
    mapper.data.splice(i, 1);
  
    console.log("removed marker "+mapItem.icon+":"+mapItem.nid+' '+mapItem.name);
  };
  </code></pre>
  
  <p>I added some more debug into to the console, going to a simple area of the map with only 2 markers <a href="http://www.trailforks.com/map/test.php?lat=49.43210641783767&amp;lon=-123.49878636730955&amp;z=14" rel="noreferrer">http://www.trailforks.com/map/test.php?lat=49.43210641783767&amp;lon=-123.49878636730955&amp;z=14</a></p>
  
  <p>I can see the markers created, then move the map a bit and see that the markers weren't re-created because they were detected in the marker object. I then move the viewport so one of the markers is off the screen and I can see that the marker is removed and the marker object length updates. But if I pan the map back over the marker is still on the map.</p>
  
  <p><img src="https://i.stack.imgur.com/z8pGf.png" alt="enter image description here"></p>