Reputation: 345
I've got a latitude/longitude value.... How can I search and get the city?
Upvotes: 9
Views: 7489
Reputation: 10363
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:
Upvotes: 10
Reputation: 6967
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}®ion={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®ion=nz
Then you can use that XML to get whatever details you need, including the City
Upvotes: 7