9

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

skaffman
  • 398,947
  • 96
  • 818
  • 769
Lennie
  • 335
  • 2
  • 4
  • 7
  • 1
    First, I'd pick a technology. I assume that you mean programmatically, and not, say, using Google. – Wonko the Sane Oct 12 '10 at 19:50
  • Possible duplicate of [How do you get the country/state/region/city/state/zip/postal from GPS coordinates?](http://stackoverflow.com/questions/1891953/how-do-you-get-the-country-state-region-city-state-zip-postal-from-gps-coordinat) – esac Jan 28 '17 at 01:59
  • You can also query wikimedia data see : https://stackoverflow.com/questions/44718137/get-wikidata-identiyfier-for-city-by-gps-location – Boas Enkler Jun 23 '17 at 10:20

2 Answers2

10

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

Pacerier
  • 86,231
  • 106
  • 366
  • 634
Maksym Kozlenko
  • 10,273
  • 2
  • 66
  • 55
  • I feel this should of been the accepted answer. Using Geonames gives you the choice to use their webservice or the opportunity to download the Geonames data to host yourself, so you're not depending on yet another third party service for an in-house solution. – Levi Roberts Aug 11 '13 at 10:14
  • is there a way of doing this in reverse, I have cities and want to get their accepted geolocation – Skyler Feb 22 '18 at 03:00
7

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

PostMan
  • 6,899
  • 1
  • 43
  • 51