views:

288

answers:

2

Hello SO,

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.

Best, Walker

+1  A: 

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.

zebediah49
Would love to, but in our usability testing a lot of smaller employers are uncomfortable posting specific addresses.
Walker
So have the employers enter a location string "Suburbs of Providence" rather than a lat/lon pair.
tpdi
We actually convert it to lat/long ourselves to store and plot it on a map (for the results page / radial based searching). The employer enters a freeform string on the job posting page
Walker
+3  A: 

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

Ossama
Take care of the Google Maps API Terms of Service:http://code.google.com/apis/maps/documentation/geocoding/#Limits"Note: the Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited. For complete details on allowed usage, consult the Maps API Terms of Service License Restrictions."
sabbour
Ahhh thanks for that!
Walker