title: Only open one infowindow at a time
body: <p>I'm creating a Google map with multiple markers. At the moment each marker has an infowindow, how can I only have one infowindow open at a time?</p>
  
  <p>At the moment it closes all windows on clicking the map.</p>
  
  <p>I know this question has been asked a few times but the code seems vastly different to mine.</p>
  
  <pre><code>// if marker contains HTML, add it to an infoWindow
  if( $marker.html() )
  {
      // create info window
      var infowindow = new google.maps.InfoWindow({
          content     : $marker.html()
      });
  
      // show info window when marker is clicked
      google.maps.event.addListener(marker, 'click', function() {
          infowindow.open( map, marker );
      });
  
      google.maps.event.addListener(map, 'click', function(event) {
          if (infowindow) {
              infowindow.close(); }
          }); 
  
  }
  </code></pre>