Get city / state from Latitude / Longitude via jquery / ajax with Google Maps geocode?

I saw several jscript / jquery implementations of this concept in the reverse order, where you can enter a zip code and get long / lat from google api maps.

However, in my case, I already have a set of coordinates, and I was interested to find out if it is possible to dynamically get the text City, State result from the API, when we feed it long / latitude via jquery?

Thanks!

+7
source share
1 answer

This process is called reverse geocoding , and Google has extensive documentation.

Example:

$.ajax({ url:'http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true', success: function(data){ alert(data.results[0].formatted_address); /*or you could iterate the components for only the city and state*/ } }); 
+16
source

All Articles