title: markerclusterer info windows
body: <p>Let me say I am still fairly new to google maps and javascript.  i've been mixing together the google store locator tutorial with some other stuff.  So far, I am using marker clusterer plus (<a href="http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.4/docs/reference.html" rel="nofollow">link</a>), basically the same as marker clusterer for google maps api v3 but with some added functionality like mouse overs and stuff like that.  I'm trying to get an info window to come up when you mouse over a cluster.  </p>
  
  <p>working demo <a href="http://fuudhub.com/demo/" rel="nofollow">here</a>. here is my full index code:</p>
  
  <pre><code>    &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
    &lt;head&gt;
      &lt;meta http-equiv="content-type" content="text/html; charset=utf-8"/&gt;
      &lt;meta name="viewport" content="initial-scale=1.0, user-scalable=no" /&gt;
      &lt;title&gt;Google Maps AJAX + mySQL/PHP Example&lt;/title&gt;
      &lt;script src="http://maps.google.com/maps/api/js?sensor=false"
              type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="markerclusterer.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
      //&lt;![CDATA[
      var map;
      var markers = [];
      var infoWindow;
      var locationSelect; 
      var markerCluster = null;
      var m;
      var p = [];
      var contentString;
  
  
      function load() {
        map = new google.maps.Map(document.getElementById("map"), {
          center: new google.maps.LatLng(40, -100),
          zoom: 4,
          mapTypeId: 'roadmap',
          mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}
        });
        infoWindow = new google.maps.InfoWindow();
        locationSelect = document.getElementById("locationSelect");
        locationSelect.onchange = function() {
          var markerNum = locationSelect.options[locationSelect.selectedIndex].value;
          if (markerNum != "none"){
            google.maps.event.trigger(markers[markerNum], 'click');
          }
        };
     }
  
     function searchLocations() {
       var address = document.getElementById("addressInput").value;
       var geocoder = new google.maps.Geocoder();
       geocoder.geocode({address: address}, function(results, status) {
         if (status == google.maps.GeocoderStatus.OK) {
          searchLocationsNear(results[0].geometry.location);
         } else {
           alert(address + ' not found');
         }
       });
     }
  
     function clearLocations() {
       infoWindow.close();
       for (var i = 0; i &lt; markers.length; i++) {
         markers[i].setMap(null);
       }
       markers.length = 0;
       locationSelect.innerHTML = "";
       var option = document.createElement("option");
       option.value = "none";
       option.innerHTML = "See all results:";
       locationSelect.appendChild(option);
     }
  
     function searchLocationsNear(center) {
       clearLocations(); 
  
       var radius = document.getElementById('radiusSelect').value;
       var searchUrl = 'genxml.php?lat=' + center.lat() + '&amp;lng=' + center.lng() + '&amp;radius=' + radius;
       downloadUrl(searchUrl, function(data) {
         var xml = parseXml(data);
         var markerNodes = xml.documentElement.getElementsByTagName("marker");
         var bounds = new google.maps.LatLngBounds();
         for (var i = 0; i &lt; markerNodes.length; i++) {
           var name = markerNodes[i].getAttribute("name");
           var address = markerNodes[i].getAttribute("address");
           var distance = parseFloat(markerNodes[i].getAttribute("distance"));
           var foodID = markerNodes[i].getAttribute("foodID");
           var restaurantName = markerNodes[i].getAttribute("restaurantName");
           var latlng = new google.maps.LatLng(
                parseFloat(markerNodes[i].getAttribute("lat")),
                parseFloat(markerNodes[i].getAttribute("lng")));
  
           createOption(name, distance, i);
           createMarker(latlng, name, address, distance, foodID, restaurantName);
           bounds.extend(latlng);
         }
         map.fitBounds(bounds);
         locationSelect.style.visibility = "visible";
         locationSelect.onchange = function() {
           var markerNum = locationSelect.options[locationSelect.selectedIndex].value;
           google.maps.event.trigger(markers[markerNum], 'click');
         };
         var clusterOptions = { zoomOnClick: false }
          var markerCluster = new MarkerClusterer(map, markers, clusterOptions);
          var contentString = 'This is an example';
          var infowindow = new google.maps.InfoWindow({
          content: contentString
          });
          google.maps.event.addListener(markerCluster, "mouseover", function (c) {
              infowindow.open(map,marker);
              //alert(contentString);
            //log("mouseover: ");
            //log("&amp;mdash;Center of cluster: " + c.getCenter());
            //log("&amp;mdash;Number of managed markers in cluster: " + c.getSize());
          });
         // google.maps.event.addListener(markerCluster, "mouseout", function (c) {
            //log("mouseout: ");
           // log("&amp;mdash;Center of cluster: " + c.getCenter());
           // log("&amp;mdash;Number of managed markers in cluster: " + c.getSize());
         // });
        });
      }
  
      function createMarker(latlng, name, address, distance, foodID, restaurantName) {
        var html = "&lt;b&gt;" + name + "&lt;/b&gt; &lt;br/&gt;" + address + "&lt;br/&gt;" + distance + "&lt;br/&gt;" + foodID + ": the food id" + "&lt;br/&gt;" + restaurantName;
        var marker = new google.maps.Marker({
          map: map,
          position: latlng
        });
        google.maps.event.addListener(marker, 'click', function() {
          infoWindow.setContent(html);
          infoWindow.open(map, marker);
        });
        markers.push(marker);
      }
  
      function createOption(name, distance, num) {
        var option = document.createElement("option");
        option.value = num;
        option.innerHTML = name + "(" + distance.toFixed(1) + ")";
        locationSelect.appendChild(option);
      }
  
      function downloadUrl(url, callback) {
        var request = window.ActiveXObject ?
            new ActiveXObject('Microsoft.XMLHTTP') :
            new XMLHttpRequest;
  
        request.onreadystatechange = function() {
          if (request.readyState == 4) {
            request.onreadystatechange = doNothing;
            callback(request.responseText, request.status);
          }
        };
  
        request.open('GET', url, true);
        request.send(null);
      }
  
      function parseXml(str) {
        if (window.ActiveXObject) {
          var doc = new ActiveXObject('Microsoft.XMLDOM');
          doc.loadXML(str);
          return doc;
        } else if (window.DOMParser) {
          return (new DOMParser).parseFromString(str, 'text/xml');
        }
      }
  
      function doNothing() {}
  
      //]]&gt;
  
  function log(h) {
         document.getElementById("log").innerHTML += h + "&lt;br /&gt;";
       }
  
    &lt;/script&gt;
    &lt;/head&gt;
  
    &lt;body style="margin:0px; padding:0px;" onLoad="load()"&gt; 
      &lt;div&gt;
       &lt;input type="text" id="addressInput" size="10"/&gt;
      &lt;select id="radiusSelect"&gt;
        &lt;option value="25" selected&gt;25mi&lt;/option&gt;
        &lt;option value="100"&gt;100mi&lt;/option&gt;
        &lt;option value="200"&gt;200mi&lt;/option&gt;
      &lt;/select&gt;
  
      &lt;input type="button" onClick="searchLocations()" value="Search"/&gt;
      &lt;/div&gt;
      &lt;div&gt;&lt;select id="locationSelect" style="width:100%;visibility:hidden"&gt;&lt;/select&gt;&lt;/div&gt;
      &lt;div id="map" style="width: 100%; height: 80%"&gt;&lt;/div&gt;
      &lt;div id="log"&gt;&lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Basically it comes down to this part, which I may just be putting in the wrong place:</p>
  
  <pre><code>var contentString = 'This is an example';
      var infowindow = new google.maps.InfoWindow({
      content: contentString
      });
      google.maps.event.addListener(markerCluster, "mouseover", function (c) {
          infowindow.open(map,marker);
  </code></pre>
  
  <p>I thought I was doing the info window correctly, but it isn't coming up.  I know the mouseover works because the commented out alert works when i test it.  any ideas what I am doing wrong?</p>