I have some problem to get lat/lng from google map in my application.
When I put in alert message ‘lat()’ or ‘lng()’ map is not rendered at all.
In the code that I put bellow on map click I get alert with ‘undefined’ message.
I want to store lat and lng in text field on page when user move map (here I try with click) but something doesn’t work here?
function initialize() {
var latlng = new google.maps.LatLng(44.012, 20.921);
var myOptions = {
zoom: 13,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
google.maps.event.addListener(map, "click", function (latlng) {
if (latlng) {
alert(latlng.lat);
}
});
}
latlngshould be in theeventobject passed in. So, in order to extract it, you would do something like this: