Converting latitude/longitude into city name? (reverse geolocating) Converting latitude/longitude into city name? (reverse geolocating) php php

Converting latitude/longitude into city name? (reverse geolocating)


FREE SOURCES (e.g. Creative Commons)

Geonames

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

Freebase

Instead of single point it takes bounded box. Call sample:

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

Geocoder.ca

Reverse geocoding for North American addresses.

Info: http://geocoder.ca/

Sample call: http://geocoder.ca/?latt=40.70771000786733&longt=-74.0109443664550&reverse=1&allna=1&geoit=xml&corner=1&jsonp=1&callback=test

Map Quest API

Using Open Street Map nominatim service:

http://open.mapquestapi.com/nominatim/v1/search?q=50.4,30.4&format=json

NON FREE SOURCES

Yahoo PlaceFinder

Documentation http://developer.yahoo.com/geo/placefinder/

Sample call:

http://where.yahooapis.com/geocode?q=38.898717,+-77.035974&gflags=R&appid=[yourappidhere]

Google Maps API

Documentation:

http://code.google.com/apis/maps/documentation/geocoding/#ReverseGeocoding


The Google Geocoder, which supports reverse geocoding returns address_components. You just need to pull out the component of the address tagged with locality and political if you just want the city name. If you want states as well they are tagged with administrative_area_level_1


Can't you just do it do full address, and then drop the street and number?

I would say it'd be more valuable to use the full address, so as to get a more accurate distance (even if you only display the city,state).

EDIT: If you do do it that way, at least it should be returned in a standard form, which you can then easily regex the data you want out of.