title: How do I clean up an InfoWindow when the associated Marker is hidden?
body: <p>I know that many of us are writing code to open an <code>InfoWindow</code> when a marker is clicked. But the <code>InfoWindow</code> will stay in place until the upper-right <strong>X</strong> is clicked, which means that setting the associated <code>Marker</code>visibility to <code>false</code> will create what is essentially an orphaned <code>InfoWindow</code>. And there could be multiple <code>InfoWindow</code> instances displayed on the Map at the same time. I guess it's simple enough for the user to just click the <code>InfoWindow</code> closed, but it feels like hiding the <code>Marker</code> should hide the associated <code>InfoWindow</code>.</p>
  
  <p>I have started writing code like the following to deal with this scenario:</p>
  
  <pre><code>google.maps.event.addListener( marker, "click", function() {
      var bubble = new google.maps.InfoWindow({
          content: buildBubbleContent( param1, param2 )
      });
      bubble.open( map, marker );
      //pretty standard stuff to here, but the next line is new (for me):
      google.maps.event.addListenerOnce( marker, "visible_changed", function() {
          bubble.close();
      });
  });
  </code></pre>
  
  <p>Is this what everyone else is doing? It feels like a design pattern that should be called a <em>ListenBack</em>. I've never seen the issue addressed in the Google Maps docs. I can't help but think that there must be a simpler mechanism built into the <code>InfoWindow</code> to take care of this automatically. Is there a standard way to do this that I have just missed?</p>