Frage

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/

War es hilfreich?

Lösung

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

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

Andere Tipps

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.

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top