5

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/

ubermensch
  • 902
  • 1
  • 12
  • 21

3 Answers3

2

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

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

ubermensch
  • 902
  • 1
  • 12
  • 21
  • That's pretty awesome. Does it return latitude and longitude as well? – Chris Henry Jul 12 '10 at 22:00
  • 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 Jul 12 '10 at 22:04
  • The Placefinder and Placemaker services became part of the [BOSS service](https://developer.yahoo.com/boss/geo/) in 2012. They are still available for **non-commercial** use, and [rate limited to 2000 queries per day per table per APP ID](https://developer.yahoo.com/boss/geo/docs/free_YQL.html#table_pf). – jonatan Dec 30 '16 at 05:44
1

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
  • 1,554
  • 8
  • 10
  • 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 Jul 10 '10 at 15:42
  • 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 Jul 10 '10 at 21:59
1

A good way to validate a city name is to treat the text as an address, and convert it to coordinates, a process called geocoding. Geocoding also provides additional data for each location identified, that you can use to make sure it conforms to your requirements.

The Google API supports geocoding, and is free up to 2500 requests per day.

You can use an existing library for interacting with the API, such as node-geocoder and geocoder-php. The libraries also support a long list of other geocoding providers.

jonatan
  • 9,011
  • 2
  • 30
  • 34