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

Walker picture Walker · Aug 3, 2010 · Viewed 32.4k times · Source

I'm working on a job board in Codeigniter PHP + jQuery where employers enter their location and we use Google Maps API to plot it. While this has had awesome usability results, the problem is when we try to display these locations to job seekers they are muddled and hard to visually discern (they read like this: "02905, 2 miles away","171 John St., 4 miles away", "Providence, RI, 10 miles away".

I want to be able to reverse geolocate from a longitude/latitude to a set level (ideally, city name) so that in the search results I can have the locations be listed like this: "Providence, RI, 10 miles away", "Providence, RI, 5 miles away", "Cranston, RI, 16 miles away".

Is there a way to reverse geocode to city? I see many examples for ways to reverse geocode to nearest addressable location, but no way to control the level.

Hope that's clear! Feel free to comment with any questions you need clarification on.

Answer

Maksym Kozlenko picture Maksym Kozlenko · Apr 6, 2011

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