javascript - Displaying latitude and longitude of Google Maps marker in InfoWindow -


how dynamically update url in google maps infowindow latitude , longitude of (movable) marker? can display infowindow @ clicked location, , can return lat , lng event.latlng.lat() , event.latlng.lng(), if try use them define variables , use variables in infowindow, uncaught referenceerror: lat not defined errors.

    var newpostmarker;     var newpost = new google.maps.infowindow({       content: '<a href="/posts/add?lat=' + lat + '&lng=' + lng + '">add new</a>'   });      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);     }); 

the variables unknown when initialize infowindow. set content-property of infowindow in click-listener.

//infowindow without properties var newpost = new google.maps.infowindow();  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.setcontent('<a href="/posts/add?lat=' + lat + '&lng=' + lng + '">add new</a>');         newpost.open(map_canvas,newpostmarker);     }); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -