views:

96

answers:

2

I've got a bunch of "locations" - some are accurate (gaborone, botswana), some are geocodes (40.75,-73.997) and some are completely useless (#siliconcape). I need to find a way to run through the list and determine the City and Country of each string and geocode, and return nulls for the invalid locations.

Is there some sort of library/service/api/method that can be used to determine whether or not a given string represents a valid geographical location? While accounting for typos, ordering errors, etc?

+6  A: 

Probably the easiest method would be to use something like the Google Geocoding API. It'll take a string and attempt to parse it to a location. You can get output as XML, JSON, CSV.

Here's some example CSV output:

input : gaborone, botswana
output: 200,4,-24.6541100,25.9087390

input : #siliconcape
output: 602,0,0,0

input : 40.75,-73.997
output: 200,8,"324 W 30th St, New York, NY 10001, USA"
mopoke
Haha, good timing, lol - just found that myself, plus sample code :)
Wogan
Note that depending of the size of your user base, the Google Geocoding API might not be the best option due to its limit of request per day. MapQuest's API, while inferior than Google's, doesn't have any limits.
Andrew Moore
"15,000 geocode requests in a 24 hour period" <-- Given that I only have 10'500 items to geocode, Google'll work perfectly :)
Wogan
A: 

I think I've found a solution - just sharing it here in case anyone else needs it:

Use Google Maps API geocoding - feed it addresses and get co-ordinates back. Details for doing it via PHP: http://www.phpriot.com/articles/google-maps-geocoding/

Wogan