Hasan Khan Hasan Khan - 1 year ago 92
HTML Question

Country state/city dropdown in html and javascript

Is there any readily available snippet that has all the countries, states and cities for showing in a drop down in html for selection?

What is standard for this? Does everyone roll their own?

The snippet can be in html, javascript, jquery plugin.

NOTE: I know how to make chained dropdown. I'm more concerned with the data rather than technique.

Answer Source

Here is the data for free - Good luck getting 33MB presented in a drop down ;)

Seems they also have a JavaScript API - (found via Best way to get user nearest city? Python/Django) to start you off with the user's (IP) location

In the foreseeable future there may be a JSON interface according to Peter Saczkowski Operations Manager | Maxmind, Inc.:

Yes, we are actually considering switching over to JSON, but don't have a timeline quite on when that will happen. If/when this happens, we'll have updates in our newsletter and on the site.

Disclaimer I'm not affiliated with MaxMind and the themselves suggest to also look at GeoNames

MaxMind World Cities with Population Last Updated: May 17th, 2011

Product Summary: Includes city, region, country, latitude and longitude. This product doesn't contain any IP addresses. It's simply a listing of all the cities in the world. For IP to city mappings, see our MaxMind City product.

Note that this product is now a free download [33 MB]. The database will be updated about once per year, since the city data doesn't change that frequently. [license]

The database uses toponymic information, based on the Geographic Names Data Base, containing official standard names approved by the United States Board on Geographic Names and maintained by the National Geospatial-Intelligence Agency. More information is available at the Maps and Geodata link at www.nga.mil. The National Geospatial-Intelligence Agency name, initials, and seal are protected by 10 United States Code Section 445.

It also uses free population data © by Stefan Helders www.world-gazetteer.com. Visit his website to download the free population data. Our database combines Stefan's population data with the list of all cities in the world.

Another free cities database is available from GeoNames.

Product Features - MaxMind World Cities with Population

Includes the following fields:
    Country Code
    ASCII City Name
    City Name
    Timezone data is available through an external lookup
Approximately 2,710,000 records. 

Database Fields
Field               Data Type       Field Description
Country Code        char(2)         ISO 3166 Country Code,
ASCII City Name     varchar(100)    Name of city or town in ASCII encoding
City Name           varchar(255)    Name of city or town in ISO-8859-1 encoding. A list of cities contained in GeoIP City is available.
State/Region        char(2)         For US, ISO-3166-2 code for the state/province name. Outside of the US, FIPS 10-4 code
Population          unsigned int    Population of city (available for over 33,000 major cities only)
Latitude            numeric (float) Latitude of city where IP is located
Longitude           numeric (float) Longitude of city where IP is located
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download