Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get City/State from Latitude/Longitude via jquery/ajax with google maps geocode?

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

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

Thanks!

like image 689
Mark Avatar asked Nov 17 '12 06:11

Mark


1 Answers

This is a process called reverse geocoding, and Google have quite extensive documentation on it.

An example would be:

$.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*/
         }
});
like image 111
kieran Avatar answered Nov 08 '22 17:11

kieran