-1

I can setup a pushpin on map but i am not able to retrieve the latitude and longitude of that point. Here is my code. Can anyone help with this?

Thanks

 function codeaddress() {
    var geocoder;
    //map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    geocoder = new google.maps.Geocoder();

    var address = document.getElementById("address").value;

    geocoder.geocode({ 'address': address }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {


            map.setCenter(results[0].geometry.location);
            var marker = new google.maps.Marker({
                animation: google.maps.Animation.BOUNCE,
                flat: false,
                map: map,
                position: results[0].geometry.location

            });

            var latt = document.getElementById("latitude");
            latt.value = results[0].geometry.location.getlatitude();
            alert(latt.value);

        } else {
            alert("Geocode was not successful for the following reason: " + status);
        }
    });

}
  • This needs basic debugging first. What exactly goes wrong where? – Pekka Mar 08 '13 at 11:15
  • Have you tried results[0].geometry.location.lat() – Rafe Mar 08 '13 at 11:21
  • Rafe, tried results[0].geometry.location.lat(). Did not get latitude. – user2147447 Mar 08 '13 at 11:30
  • Chrome was not showing the updated pages. Any code changes that i made in javascript were not reflecting when i run the application. The part of the code where i was trying to retrieve the latitude and longitude was added at a later point. These changes were not reflecting. When i deleted browsing history on chrome, i was able to see the changes. – user2147447 Mar 08 '13 at 20:34

1 Answers1

1

try using .lat() instead of .getLatitude().

see the API about the LatLng class: https://developers.google.com/maps/documentation/javascript/reference#LatLng

klaasman
  • 856
  • 7
  • 15