Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I'm trying to create some dialogs in my web-app that can auto-suggest possible Countries, States, Cities and Zips in a form.

I was planning on storing this information in a database, and making calls to it from AJAX as the user types.

I don't want anything overly complicated like the Geonames database that I was offered when I asked this question over at the GIS stackexchange.

I installed the Geonames database on my mysql server, but I found that it was more like points on the map (things like schools, stores etc) than it was just individual Countries, States, Cities and Zipcodes.

Please let me know if I am oversimplifying the problem, as it's entirely possible that I am.

share|improve this question
2  
I think we need more info from you about how you're planning on auto-populating these fields. Is it based on GeoIP info? Are you trying to calculate it based on a partial address? Are you using proximity to a known address/zip? Are you mapping a phone number/area code to city/zip? Or are you just autocompleting based on what the user types? –  Lèse majesté Dec 6 '11 at 7:29
1  
I'd say using a proximity to a known address/zip. I want to group together locations (i.e. Country, State, City and Zip) that a user enters so they can be identified between multiple records as the same location. –  leeand00 Dec 6 '11 at 22:29

3 Answers 3

up vote 4 down vote accepted

One source is MaxMind. I haven't looked at their data, so I can comment on how good it is.

You will still need to make a decision about what to do if the exising, real-world city is not in your database.

share|improve this answer
1  
Note the important bit of the license agreement: All advertising materials and documentation mentioning features or use of this database must display the following acknowledgment: "This product includes data created by MaxMind, available from maxmind.com/"; –  leeand00 Dec 8 '11 at 7:26
    
On the whole though it looks pretty good! :) Thanks! Also opening this file is kind of a pain, but this thread solves it, since it's double zipped: bbs.archlinux.org/viewtopic.php?id=129771 –  leeand00 Dec 8 '11 at 7:53

This blog post on a Coldfusion blog explains one implementation of what I think you're trying to do. It's pretty straight forward:

  1. He found a cheap paid (regularly updated) source that provides their app with up-to-date city/zip/state/geo-coordinate records and imported it into an SQL database.
  2. He created a user-defined function that would measure the distance between two sets of long/lat coordinates.
  3. Then use the UDF to perform queries to find locations within a particular distance or check the distance between two locations.
share|improve this answer

It seems like you want a valid, accurate address from the user. Each country varies widely, but in the USA, the USPS maintains a current database of valid addresses, and everything you can possibly imagine about them. Vendors of proper address verification products (that can validate and standardize wrong/incomplete addresses) are CASS-Certified by the USPS.

There are a few options for doing what you want to do. The easiest of all, and most affordable (even free) is an address validation API. I work at a company called SmartyStreets which offers such an API called LiveAddress. There's a simple Javascript implementation you can just copy+paste into your website. As the user submits the form, they'll be prompted to choose a valid address based on what they typed. I am sure this will be of some use to you.

share|improve this answer
    
That would be a good thing to use to ensure the validity of the database, thank you for adding it. What I really want to be able to do is associate a record (an address) with a particular City, State, and Zip so that I can search for records associated with a particular City, State or Zip. –  leeand00 Jan 23 '12 at 5:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.