# OT: Country -\> (State) -\> City/Town (XML/JSON)

**URL:** <https://www.ruby-forum.com/t/ot-country-state-city-town-xml-json/186486>\
**Category:** Rails\
**Created:** [April 7, 2010, 9:04pm UTC](https://www.ruby-forum.com/t/ot-country-state-city-town-xml-json/186486 "2010-04-07T21:04:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ants\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@Ants\_P](https://www.ruby-forum.com/u/Ants_P)\
**Post date:** [April 7, 2010, 9:04pm UTC](https://www.ruby-forum.com/t/ot-country-state-city-town-xml-json/186486/1 "2010-04-07T21:04:33Z")

</div>

Does anyone know where I can find Country -\> (State) -\> City/Town data  
in  
easy to read format (XML/JSON)?

I need it for my application and would like a good base of  
countries/states/towns/cities before I start asking users to add missing  
information.

Regards

-ants

–  
100% naturally selected. 0% designed.

---

<div class="post-metadata">

**Author:** ![Ants\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@Ants\_P](https://www.ruby-forum.com/u/Ants_P)\
**Post date:** [April 9, 2010, 5:25am UTC](https://www.ruby-forum.com/t/ot-country-state-city-town-xml-json/186486/2 "2010-04-09T05:25:53Z")

</div>

“Ants P.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote  
in message  
news:removed\_email\_address@domain.invalid…

> Does anyone know where I can find Country → (State) → City/Town data in
> 
> > easy to read format (XML/JSON)?

There is a databse that provides city (and state/province information  
for  
the US and Canada). It is freely available, but requires a short message  
in  
the legal section of your site, as well as in any  
documention/advertisements  
that mention the address portion of the product. If sounds acceptable,  
then  
what you want is:

MaxMind’s worldcitiespop.txt database. The database is a text file  
encoded  
using the ISO-8859-1 encoding. It is a simple comma seperated value  
(CSV)  
database. The fields are CountryCode, ASCIICityName, CityName,  
StateCode,  
Population, Latitude, Longitude.

You can ignore the last 3 fields. You will need a database to match  
CountryCodes to country names, but MaxMind provides one. A trivial 2  
feild  
CSV file. You will also need a State/CanadaProvince-code to name, and  
MaxMind also provides that too, as a trivial 2 field CSV file.

A few quick gotchas: The file is 130MB uncompressed, and is a 30 MB  
download. The first line is not a record, but gives the feild names. A  
few  
cities might have country codes of “A1”,“A2”,“EU”,or “AP”. you should  
not  
include those, since they are special codes for the geoIP database. The  
statecode feild has a numeric region code for countries other than the  
US or  
Canada, I’d advise you ignore them.

The main database is at:  
[http://www.maxmind.com/download/worldcities/worldcitiespop.txt.gz](http://www.maxmind.com/download/worldcities/worldcitiespop.txt.gz)  
The license is at:  
[http://geolite.maxmind.com/download/geoip/database/LICENSE\_WC.txt](http://geolite.maxmind.com/download/geoip/database/LICENSE_WC.txt)

The Country Code and City Code databases are small enough they provide  
them  
as text on html pages: [GeoIP2 Release Notes - 2021 Archive](http://www.maxmind.com/app/iso3166) and  
[http://www.maxmind.com/app/iso3166\_2](http://www.maxmind.com/app/iso3166_2) respectively.

I hope this helps.
