Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Names of all cities [closed]

Tags:

php

mysql

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?
like image 751
Michal Avatar asked Jul 15 '14 07:07

Michal


People also ask

Are there any closed cities in the US?

Mercury, Nevada is situated within the Nevada Test Site, the primary testing location of American nuclear devices from 1951 to 1992, currently called Nevada National Security Site, and is currently closed as part of this site. Oak Ridge, Tennessee was a closed city during the Manhattan Project.

What nuclear cities closed?

A closed city or closed town is a settlement with travel and residency restrictions in the Soviet Union, some of its successor countries, or the United States.

Does Russia still have closed cities?

What is this? Today, most of the formerly closed Russian cities are open to the public but there are a few of them which are still hidden by the authorities. It's estimated that today, there are around 40 closed Russian cities and more than 1.5 million people live here.


1 Answers

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

like image 177
Burhan Khalid Avatar answered Oct 09 '22 23:10

Burhan Khalid