views:

33

answers:

2

Hello,

My problem concerns validating/normalising a user's input for the combination of Country and 'City' during registration. Ideally, I want functionality similar to the OkCupid (http://www.okcupid.com/signup) registration page where this question is asked. Loss of focus on the City input field validates the input somehow, and it is amazingly good at it. I tried a small country town in rural Australia (pop. < 6000) and a random town in Finland, and both were validated correctly and quickly.

Normalising/Validating is important because I would like to normalise the 'City' field of a user-generated event entity to allow matching against users in the same location.

This validation makes sense both from an application logic perspective (I don't want to deal with the 'NYC' = 'New York City' = 'New York, New York' = 'New York' quagmire), and a user perspective (other users understanding a user's location).

I'm using PHP and jQuery if that makes a difference, but any solution at this point is more promising than nothing!

Thanks in advance!

EDIT : Solved! Yahoo provides the PlaceMaker API - free-form location string parsing! 50,000 requests per day limit:

http://developer.yahoo.com/geo/placemaker/

+1  A: 

For validation purposes, the following site has references to a very comprehensive (and free!) international cities database.

http://earth-info.nga.mil/gns/html/

Normalising is a much harder problem. For that, you'd most likely need to tap into a proprietary product. Google maps may be one option.

btreat
Have you ever used this database? The OpenStreetMap wiki mentions some concerns with the data (http://wiki.openstreetmap.org/wiki/GEOnet_Names_Server). Any thoughts?
ubermensch
On the whole it is good and useful, but it does have some of the quirks mentioned at the link you provided. It also tends to work better for cities whose native names are spelled with the latin character set. The Anglicisation of the names of some Asian cities can sometimes be problematic.
btreat
+1  A: 

Solved! Yahoo provides the PlaceMaker API - free-form location string parsing! 50,000 requests per day limit:

http://developer.yahoo.com/geo/placemaker/

ubermensch
That's pretty awesome. Does it return latitude and longitude as well?
Chris Henry
Yep, everything. The way its put together means that it basically telescopes to as much or as little info as you give it, while providing a 'quality' rating depending on what you want to know. E.g. if you want cross-street information at a resolution it doesn't have, it provides something nearby while lowering the 'quality' value it returns.
ubermensch