title: Zoom out event for google maps?
body: <p>I'm trying to maintain a constant set of sample markers on my maps for easy viewing. I populate my maps with a random selection of markers from the database up to a certain number during pan and zoom. The main problem is to replace markers falling out-of-bounds with new markers in-bounds.<br /><br /> The code below works quite well except for zooming out.
  As I zoom out I want to repeatedly refresh the map with a new set of random markers, up to a certain number and spread evenly over the map. The problem is there is a zoom_changed event but it doesn't seem to distinguish between in and out.<br /><br />
  Any suggestions?</p>
  
  <blockquote>
  <pre><code>      google.maps.event.addListener(map, 'idle', function() {
              bounds = map.getBounds();
              var southWest = bounds.getSouthWest();
              var northEast = bounds.getNorthEast();
              var north = northEast.lat();
              var south = southWest.lat();
              var west = southWest.lng();
              var east = northEast.lat();
              var marnum = 20;
              $.post('pzparsers/pzparsers.php', {north:north, south:south, west:west, east:east, marnum:marnum}, function(response){
                  eval(response);
                  bounds = map.getBounds();
                  if(oldmarkers.length == 0 &amp;&amp; newmarkers.length !== 0){
                      //b = $.extend( true, {}, a );
                      for (var i = 0; i &lt; newmarkers.length; i++) {
                          oldmarkers[i] = newmarkers[i];
                          oldmarkers[i].setMap(map);
                      }
                  } else if (oldmarkers.length !== 0 &amp;&amp; newmarkers.length !== 0){
                      for (var i = 0; i &lt; oldmarkers.length; i++){
                          if(!bounds.contains(oldmarkers[i].getPosition())){
                              oldmarkers[i].setMap(null);
                              oldmarkers[i] = newmarkers[i];
                              oldmarkers[i].setMap(map);
                          }
                      }
                  }                       
              }); 
          });
  </code></pre>
  </blockquote>
  
  <p>The php: -</p>
  
  <blockquote>
  <pre><code>  $output .= "newmarkers.length = 0;\n";
      if($mrk_cnt &gt; 0){
          for ($lcnt = 0; $lcnt &lt; $mrk_cnt; $lcnt++){
              $output .= "var point = new google.maps.LatLng($lat[$lcnt], $lng[$lcnt]);\n";
              $output .= "var mrktx = \"$inf[$lcnt]\";\n";
              $output .= "var infowindow = new google.maps.InfoWindow({ content: mrktx });\n";
              $output .= "var marker = new google.maps.Marker({position: point, icon: $icon[$lcnt], title: '$inf[$lcnt]  $begin[$lcnt] - $end[$lcnt]'});\n";
              $output .= "google.maps.event.addListener(marker,'click', function() {infowindow.open(map,marker);});\n";
              //$output .= "marker.setMap(map);\n";       
              $output .= "newmarkers.push(marker);\n";
          }
      }
  </code></pre>
  </blockquote>