Names of all cities

mysql, php

Solution

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).

Problem

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? - 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? - 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? - Would you suggest completely different solution?

Original source

Related problems