title: Displaying latitude and longitude of Google Maps marker in InfoWindow
body: <p>How do I dynamically update a URL in my Google Maps InfoWindow with the latitude and longitude of my (movable) marker? I can display an InfoWindow at a clicked location, and I can successfully return lat and lng with <code>event.latLng.lat()</code> and <code>event.latLng.lng()</code>, but if I try to use them to define variables and then use those variables in my InfoWindow, I get <code>Uncaught ReferenceError: lat is not defined</code> errors.</p>
  
  <pre><code>var newpostmarker;
  var newpost = new google.maps.InfoWindow({
      content: '&lt;a href="/posts/add?lat=' + lat + '&amp;lng=' + lng + '"&gt;Add New&lt;/a&gt;'
  });
  
  function placeNewPostMarker(location) {
      if (newpostmarker) {
          newpostmarker.setPosition(location);
      } else {
          newpostmarker = new google.maps.Marker({
              position: location,
              map: map_canvas,
          });
      }
      newpostmarker.setVisible(false);
  }
  
  google.maps.event.addListener(map_canvas, 'click', function (event) {
      var lat = event.latLng.lat();
      var lng = event.latLng.lng();
      alert("Lat=" + lat + "; Lng=" + lng);
      placeNewPostMarker(event.latLng);
      newpost.open(map_canvas, newpostmarker);
  });
  </code></pre>