How do I alert the latitude in this Google Maps javascript?

As you can see, there is a line in there that does an alert. It's "undefined". Whereas if I just alert results[0].geometry.location, it alerts (41.321, 41.556).

I just want to alert it and set it (as an int) to one of my id_lat and id_longs...

        var address = $("#addressinput").val();
        geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            $("#map_canvas_holder").show().css("background-color", "#E6E6FA").animate({"background-color":"#f5f5f5"}, 800);
            var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);  

            alert(results[0].geometry.location[1]); //this is undefined.


            var marker = new google.maps.Marker({
                map: map, 
                position: results[0].geometry.location,
          } else {
        return false;


Use results[0] to get the latitude and results[0].geometry.location.lng() for the longitude.

If you look at the API, location isn't an array (that's the main issue here), it's a property, so .location is the correct way to access it, not .location[0].

The official documentation is a bit hard to find for specific types, but here are updated docs on that location (a LatLng type):

The toString() is what you're getting in an alert (lat, long), there's also .lat() for latitude and .lng() for longitude, like this:


Need Your Help

How to get a cookie from an AJAX response?

jquery html ajax google-chrome

I have a $.ajax request on the same domain and I want to read the cookie. It keeps returning null.