title: Variable becomes undefine in subfunction
body: <p>Im using Google Maps javascript api to show a map full of markers of locations. The markers display but once they are clicked on the console gives the error: "Uncaught TypeError: Cannot read property '0' of undefined" at <code>infowindow.setContent('&lt;div&gt;&lt;p&gt;'+locations[i][0]+'&lt;/p&gt;&lt;/div&gt;');</code> . I found that the problem was the script didn't know what <code>i</code> was. I have tested to this conclusion by substituting <code>i</code> with a number and it works without error. So far I have tried making <code>i</code> a global variable and testing its value as <code>window.i</code>. It still didn't work, but in console it showed its last count. Is there something I'm doing wrong?</p>
  
  <pre><code>function initialize() {
      var locations = [&lt;?php echo $jscript; ?&gt;];
  
      map = new google.maps.Map(document.getElementById('map-canvas'), {
          zoom: 8,
          center: new google.maps.LatLng(32.639594, -97.117879),
          mapTypeId: google.maps.MapTypeId.ROADMAP
      });
  
      var infowindow = new google.maps.InfoWindow();
  
      var marker = '';
      var i = 0;
      for (i = 0; i &lt; locations.length; i++) {
          var geocoder_map = new google.maps.Geocoder();
          var addlocat;
  
          geocoder_map.geocode({'address': locations[i][0]}, function (results, status) {
              if (results) {
                  addlocat = results[0].geometry.location;
  
                  marker = new google.maps.Marker({
                      position: addlocat,
                      map: map
                  });
  
                  google.maps.event.addListener(marker, 'click', (function (marker, i) {
                      return function () {
                          infowindow.setContent('&lt;div&gt;&lt;p&gt;' + locations[i][0] + '&lt;/p&gt;&lt;/div&gt;');
                          infowindow.open(map, marker);
                      }
                  })(marker, i));
  
              }
          });
      }
  }
  
  google.maps.event.addDomListener(window, 'load', initialize);
  </code></pre>