markzzz
markzzz

Reputation: 48015

How to get city from lat/lng with Google Maps V3?

This is what I've done :

var geocoder = new google.maps.Geocoder();
var location = new google.maps.LatLng(45.930976,10.639744);

geocoder.geocode({ 'latLng': location  }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
        alert(results[1].address_components[0].long_name);
    }
}); 

but I'd like to prefeer not using address_components[i] which parameter, due to the fact it could be different for each request. How is the parameter to get the city? (or location, or country, and so on...).

Upvotes: 1

Views: 2092

Answers (1)

huzzah
huzzah

Reputation: 1805

Not sure if I'm reading the API right (Geocoding API doc), but it looks like it might be 'types:locality'

Upvotes: 3

Related Questions