4

以下网络服务将为我提供所有国家/地区。我想得到所有的州和省。我怎样才能做到这一点?

http://ws.geonames.org/countryInfo

似乎唯一的方法是在这里http://www.geonames.org/export/web-services.html注册一个 API 用户名,然后尝试调用类似http://api.geonames.org/ postalCodeSearch?country=COUNTRY_CODE&username=demo其中 COUNTRY_CODE 是一个变量,我必须通过遍历每个国家来填充。

是否有更简单/更好的方法来获取所有州/省信息?像http://ws.geonames.org/stateInfo这样的东西会很棒!

4

1 回答 1

1

我发现的最好的是:

CREATE TABLE `countries` (
  `id` smallint(5) unsigned NOT NULL auto_increment,
  `name` varchar(40) NOT NULL,
  `abbreviation` varchar(4) NOT NULL,  
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

CREATE TABLE `states` (
  `id` smallint(5) unsigned NOT NULL auto_increment,
  `country_id` smallint(5) unsigned NOT NULL,
  `name` varchar(100) NOT NULL,
  `abbreviation` varchar(3) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

INSERT INTO countries (name, abbreviation) VALUES ('Canada', 'CAN');
INSERT INTO countries (name, abbreviation) VALUES ('United States of America', 'USA');

INSERT INTO states (country_id, name, abbreviation) VALUES ('1', 'Alberta', 'AB');
INSERT INTO states (country_id, name, abbreviation) VALUES ('1', 'British Columbia', 'BC');
INSERT INTO states (country_id, name, abbreviation) VALUES ('1',  'Manitoba', 'MB');
INSERT INTO states (country_id, name, abbreviation) VALUES ('1',  'New Brunswick', 'NB');
INSERT INTO states (country_id, name, abbreviation) VALUES ('1',  'Newfoundland and Labrador', 'NL');
INSERT INTO states (country_id, name, abbreviation) VALUES ('1',  'Northwest Territories', 'NT');
INSERT INTO states (country_id, name, abbreviation) VALUES ('1',  'Nova Scotia', 'NS');
INSERT INTO states (country_id, name, abbreviation) VALUES ('1', 'Nunavut', 'NU');
INSERT INTO states (country_id, name, abbreviation) VALUES ('1',  'Ontario', 'ON');
INSERT INTO states (country_id, name, abbreviation) VALUES ('1',  'Prince Edward Island', 'PE');
INSERT INTO states (country_id, name, abbreviation) VALUES ('1',  'Québec', 'QC');
INSERT INTO states (country_id, name, abbreviation) VALUES ('1',  'Saskatchewan', 'SK');
INSERT INTO states (country_id, name, abbreviation) VALUES ('1',  'Yukon Territory', 'YT');


INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Alaska', 'AK');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Alabama', 'AL');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Arizona', 'AZ');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Arkansas', 'AR');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'California', 'CA');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Colorado', 'CO');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Connecticut', 'CT');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Delaware', 'DE');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'District of Columbia', 'DC');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Florida', 'FL');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Georgia', 'GA');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Hawaii', 'HI');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Idaho', 'ID');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Illinois', 'IL');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Indiana', 'IN');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Iowa', 'IA');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Kansas', 'KS');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Kentucky', 'KY');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Louisiana', 'LA');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Maine', 'ME');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Maryland', 'MD');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Massachusetts', 'MA');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Michigan', 'MI');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Minnesota', 'MN');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Mississippi', 'MS');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Missouri', 'MO');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Montana', 'MT');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Nebraska', 'NE');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Nevada', 'NV');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'New Hampshire', 'NH');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'New Jersey', 'NJ');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'New Mexico', 'NM');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'New York', 'NY');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'North Carolina', 'NC');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'North Dakota', 'ND');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Ohio', 'OH');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Oklahoma', 'OK');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Oregon', 'OR');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Pennsylvania', 'PA');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Puerto Rico', 'PR');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Rhode Island', 'RI');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'South Carolina', 'SC');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'South Dakota', 'SD');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Tennessee', 'TN');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Texas', 'TX');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Utah', 'UT');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Vermont', 'VT');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Virginia', 'VA');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Washington', 'WA');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'West Virginia', 'WV');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Wisconsin', 'WI');
INSERT INTO states (country_id, name, abbreviation) VALUES ('2', 'Wyoming', 'WY');

我从这里得到的http://www.prioninteractive.com/2011/02/mysql-sql-for-generating-canada-and-usa-provincestate-tables/

这是平常的事;想不到这么难找...

希望这对其他人有帮助。

于 2013-04-23T23:14:38.877 回答