Tim van Rens Tim van Rens - 2 months ago 17
Javascript Question

undefined Lat and Long google maps

I would like the lat and long coordinates. instead of the coordinateds i get this

location:
Waalre, Nederland
Address: Waalre, Nederland
Latitude: undefined
Longitude: undefined




<script type="text/javascript">
google.maps.event.addDomListener(window, 'load', intilize);
function intilize() {
var autocomplete = new google.maps.places.Autocomplete(document.getElementById("txtautocomplete"));

google.maps.event.addListener(autocomplete, 'place_changed', function () {

var place = autocomplete.getPlace();
var location = "Address: " + place.formatted_address + "<br/>";
location += "Latitude: " + place.geometry.location.A + "<br/>";
location += "Longitude: " + place.geometry.location.F;
document.getElementById('lblresult').innerHTML = location
});

};

</script>

<span>location:</span><input type="text" id="txtautocomplete" style="width:200px" placeholder="enter the adress"/>
<label id="lblresult"></label>
</body>

Answer

mate,

.geometry.location.A/.geometry.location.F are not accessible , use lat() and lng()

change to this :

    location += "Latitude: " + place.geometry.location.lat() + "<br/>";
    location += "Longitude: " + place.geometry.location.lng();