user1465506
user1465506

Reputation: 111

Google map geocode api returns incorrect lat/lng key

I'm using the Google Maps JavaScript API v3

The following code is almost straight out of a google sample code but I'm experiencing a strange issue. results[0].geometry.location has the keys "k" and "D" instead of "lat" and "lng".

Any idea why this might be happening?

    mapui.geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            console.log(results[0]);
            var lat = results[0].geometry.location['lat'];
            var lng = results[0].geometry.location['lng'];
        }
    })

notice the keys in locations

Upvotes: 1

Views: 970

Answers (1)

MrUpsidown
MrUpsidown

Reputation: 22490

You have to use the lat() and lng() functions. The geometry.location is a LatLng class.

var lat = results[0].geometry.location.lat();
var lng = results[0].geometry.location.lng();

https://developers.google.com/maps/documentation/javascript/reference#GeocoderGeometry https://developers.google.com/maps/documentation/javascript/reference#LatLng

Look in __proto__ in your javascript console and you will find the available methods.

Upvotes: 4

Related Questions