Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

City By GPS Location Latitude/Longitude

I've got a latitude/longitude value.... How can I search and get the city?

like image 957
Lennie Avatar asked Oct 12 '10 19:10

Lennie


2 Answers

If you're looking for free (as freedom) sources, you can use Geonames API findNearbyPlaceName.

For example the following returns nearest Placename:

http://api.geonames.org/findNearbyPlaceName?lat=47.3&lng=9&username=demo

More information is available here

http://www.geonames.org/export/web-services.html#findNearbyPlaceName

Another option is getting data from Freebase. Instead of single point it takes bounded box:

http://api.freebase.com/api/service/geosearch?location=[30.2,50.4,30.6,50.8]&location_type=/location/citytown&inside=true&indent=1

like image 90
Maksym Kozlenko Avatar answered Oct 24 '22 12:10

Maksym Kozlenko


Using the google maps api, here is an example to get the address in XML format.

http://maps.google.com/maps/api/geocode/xml?latlng={latlng}&sensor={sensor}&region={region}

Where latlng = 0,0 sensor = false, and region = country code, so for my old address it would be

http://maps.google.com/maps/api/geocode/xml?latlng=-43.893792,171.7592620&sensor=false&region=nz

Then you can use that XML to get whatever details you need, including the City

like image 39
PostMan Avatar answered Oct 24 '22 13:10

PostMan