9

Problem

I want to provide users of my web with city selection when they are registering to this web app. I have to be sure, that the address is correct, because I am sending them regular mail consequently in order to verify their address. And nonsense or misspelled city names can cause trouble for me.

Current state

Up to now, I always used a database table with names of all cities in my country. My country has about 600 cities, so it wasn't problem to populate table manually from wikipedia. However, recently I am planning to allow registration from other countries including Germany and USA and that should be problem.

Question

I would like to ask you how city selection/validation could be solved professionally?

  1. Do I have to create a big table for all cities (with country foreign key) and populate it using some import scripts? Where should I look for data then? Have such import scripts already exist?
  2. Or is it better to use some third-side service to provide/validate city names. What would happen when this service went offline? Do you know such service? Could you give me example how to use it?
  3. Would you suggest completely different solution?
Michal
  • 1,955
  • 5
  • 33
  • 56
  • 3
    Good question, I'm interested in what the answers are going to be – Jonan Jul 15 '14 at 07:28
  • Maybe a combination of jQuery autocomplete and AJAX: http://jqueryui.com/autocomplete/#default – Paul Dessert Jul 15 '14 at 07:28
  • 2
    Really sorry, but this question is just too broad. Stackoverflow is meant for programming problems where you need to show your current code, state where the problem lies and what your expected outcome is. – nl-x Jul 15 '14 at 07:29
  • https://maps.googleapis.com/maps/api/geocode/json?address=san+andreas – Cthulhu Jul 15 '14 at 07:30
  • 1
    [This may be helpful to you](http://stackoverflow.com/questions/1794833/list-of-cities-by-country) – billyonecan Jul 15 '14 at 07:31
  • On hold? The questions are clear. How can I ask about a one specific subject, If I am considering several alternatives and I am not skilled in this topic? The answers were very helpful for me especially one from @billyonecan, thank you billy. – Michal Jul 16 '14 at 06:47

2 Answers2

5

I don't think its practical to keep a database of city/states because you will then have another problem of keeping this updated and making sure you store all variations of a city name as well.

Its better to use a third party web service. The United States Postal Service (USPS) provides a web service you can use. You can send this any address, and it will return to you a cleaned/verified version (if the address is valid), or an error message.

Similar services can be found for other countries or by using the APIs of multi-national courier companies like DHL or FedEx.

However, as you are planning to ship goods - why not go with a service like Easypost? Not only do they provide a comprehensive api, but they will also validate addresses and even calculate shipping rates (should you wish).

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
0

One of Third party site for address validation is Smarty Streets

For more info u can visit this link

Community
  • 1
  • 1
khanz
  • 205
  • 1
  • 9