获取.NET中的州和省份

时间:2013-04-20 18:35:23

标签: c# asp.net web-services api geolocation

以下网络服务将为我提供所有国家/地区。我希望得到所有州和省。我怎么能这样做?

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之类的东西太棒了!

1 个答案:

答案 0 :(得分: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/

这是常见的事情;我不敢相信它很难找到......

希望这会帮助别人。