获得 2 个字母的州/省缩写 [英] get 2 letter state/province abbreviation
问题描述
所以我使用 GeoNames API 来获取国家和州/省信息,我用这些信息填充表单中的选择下拉列表.此表单将其信息提交给 SOAP Web 服务,而 SOAP 服务器仅了解 2 个字母形式的国家和州/省数据.IE.CA 代表加拿大,US 代表美国.GeoNames API 为不同的国家/地区提供此信息,但不为其子(州/省)提供此信息.
So I'm using the GeoNames API to get country and state/province information which I'm using to populate select dropdowns in a form. This form submits it's information to a SOAP web service and the SOAP Server only understands the country and state/province data in 2 letter form. ie. CA for Canada, US for United States. The GeoNames API provides this information for the different countries but not for their children (states/provinces).
有谁知道如何从 GeoNames 获取州/省/领地的 2 个字母缩写,或者我可以尝试其他 API 吗?
Does anyone know how to get the 2 letter abbreviation for a state/province/territory from GeoNames or is there another API I can try?
推荐答案
我不熟悉 GeoNames API,但您似乎正在获取 ISO-3166 alpha-2 国家/地区代码:http://www.iso.org/iso/country_codes.htm
I'm not familiar with the GeoNames API, but it appears you are getting the ISO-3166 alpha-2 country codes: http://www.iso.org/iso/country_codes.htm
如果是,则 ISO 3166-2:2007 定义了州和省.以上页面介绍了如何购买数据库等格式的信息.
If so, ISO 3166-2:2007 defines states and provinces. The page above describes how to purchase the information in database and other formats.
除非需要从 Web 服务获取此信息,否则我认为从某种类型的静态文件中读取下拉列表并创建一种偶尔更新的机制会更简单.这种类型的数据不应经常更改(好吧,至少在稳定的国家/地区).
Unless its a requirement to get this information from a web service, I would think it's simpler to read the dropdown list from some type of static file, and create a mechanism for occasional updates. This type of data shouldn't change that often (well, in stable countries at least).
这篇关于获得 2 个字母的州/省缩写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!