title: Labels OR tootlips on polygons in Google Maps when reading from external XML file
body: <p>I need help displaying labels or tooltips on polygons in Google Maps. </p>
  
  <p>I'm generating an XML file from MySQL and passing the result to Google Maps. The label text should be taken from the "name" attribute in the "subdivision" tag of the XML file (For example, 42033, 44001, etc. from the XML example in the code). Below is my working code, as well as a sample of XML that can be used to test it. Any help would be greatly appreciated.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  
  &lt;title&gt;map.php&lt;/title&gt;
  
  &lt;!-- EXAMPLE XML
  &lt;subdivisions&gt;
      &lt;subdivision name="42033"&gt;
          &lt;coord lat="40.64611090684065" lng="-73.97076976149259"/&gt;
          &lt;coord lat="40.645316667618836" lng="-73.97054554390671"/&gt;
          &lt;coord lat="40.64516421854578" lng="-73.9719467951965"/&gt;
          &lt;coord lat="40.645862324545774" lng="-73.97208574769395"/&gt;
          &lt;coord lat="40.64600111018018" lng="-73.97174398166794"/&gt;
          &lt;coord lat="40.64637857107249" lng="-73.97084113795663"/&gt;
          &lt;coord lat="40.64611090684065" lng="-73.97076976149259"/&gt;
      &lt;/subdivision&gt;
      &lt;subdivision name="44001"&gt;
          &lt;coord lat="40.6397169858144" lng="-73.99082364793345"/&gt;
          &lt;coord lat="40.639155386804205" lng="-73.99140800923699"/&gt;
          &lt;coord lat="40.64077040176035" lng="-73.99407692009133"/&gt;
          &lt;coord lat="40.64124779897801" lng="-73.99336253671026"/&gt;
          &lt;coord lat="40.641728290946446" lng="-73.9926445605762"/&gt;
          &lt;coord lat="40.6422049040861" lng="-73.99192812375553"/&gt;
          &lt;coord lat="40.64268589050536" lng="-73.99121277446031"/&gt;
          &lt;coord lat="40.64139006146806" lng="-73.98906715919247"/&gt;
          &lt;coord lat="40.64083622307287" lng="-73.98966136464998"/&gt;
          &lt;coord lat="40.64027520619966" lng="-73.99024413671366"/&gt;
          &lt;coord lat="40.6397169858144" lng="-73.99082364793345"/&gt;
      &lt;/subdivision&gt;
  &lt;/subdivisions&gt;
  --&gt;
  
  
  &lt;meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'/&gt;
  
  
  &lt;script src="https://maps.googleapis.com/maps/api/js?key=[API_KEY]"&gt;&lt;/script&gt; &lt;!-- API KEY REMOVED FOR PRIVACY --&gt;
  &lt;script type="text/javascript"&gt;
      function initialize() {
          var mapOptions = {
              zoom: 12,
              center: new google.maps.LatLng(40.7,-74),
              mapTypeId: google.maps.MapTypeId.ROADMAP
          };
  
          var map = new google.maps.Map(document.getElementById('map-canvas'),  mapOptions);
          var arr = new Array();
          var polygons = [];
          var bounds = new google.maps.LatLngBounds();
  
          downloadUrl("phpsqlajax.php", function(data) { // OUTPUT LOOKS IDENTICAL TO EXAMPLE XML ABOVE, FIRST ARGUMENT CAN BE SUBSTITUTED WITH AN XML FILE
              var xml = data.responseXML;
              var subdivision = xml.getElementsByTagName("subdivision");
              for (var i = 0; i &lt; subdivision.length; i++) 
              {
                  arr = [];
                  var coordinates = xml.documentElement.getElementsByTagName("subdivision")[i].getElementsByTagName("coord");
                  for (var j=0; j &lt; coordinates.length; j++) {
                      arr.push( new google.maps.LatLng(
                      parseFloat(coordinates[j].getAttribute("lat")),
                      parseFloat(coordinates[j].getAttribute("lng"))
                      ));
  
                      bounds.extend(arr[arr.length-1])
                  }
                  polygons.push(new google.maps.Polygon({
                      paths: arr,
                      strokeColor: '#FF0000',
                      strokeOpacity: 0.8,
                      strokeWeight: 1,
                      fillColor: '#FF0000',
                      fillOpacity: 0.25
                  }));
                  polygons[polygons.length-1].setMap(map);
              }
          });
          // map.fitBounds(bounds); // DOES NOT WORK FOR LARGE XML FILES
          map.setCenter(new google.maps.LatLng(40.7,-74));
      }
  
      function downloadUrl(url, callback) {  
          var request = window.ActiveXObject ? 
          new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest;   
          request.onreadystatechange = function() {    
              if (request.readyState == 4) {            
                  callback(request);    
              } 
          };   
          request.open('GET', url, true);  
          request.send(null); 
      }
  
      /**
      * Parses the given XML string and returns the parsed document in a
      * DOM data structure. This function will return an empty DOM node if
      * XML parsing is not supported in this browser.
      * @param {string} str XML string.
      * @return {Element|Document} DOM.
      */
      function xmlParse(str) {
          if (typeof ActiveXObject != 'undefined' &amp;&amp; typeof GetObject != 'undefined') {
              var doc = new ActiveXObject('Microsoft.XMLDOM');
              doc.loadXML(str);
              return doc;
          }
  
          if (typeof DOMParser != 'undefined') {
              return (new DOMParser()).parseFromString(str, 'text/xml');
          }
  
          return createElement('div', null);
      }
  
      google.maps.event.addDomListener(window, 'load', initialize);
  &lt;/script&gt;
  
  
  &lt;style&gt;
  #map-canvas { position: absolute; top: 0px; right: 0; bottom: 0px; left: 0; }
  &lt;/style&gt;
  
  
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div id="map-canvas"&gt;&lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>