Search code examples
apigeolocationgeonames

get 2 letter state/province abbreviation


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).

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?


Solution

  • 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

    If so, ISO 3166-2:2007 defines states and provinces. The page above describes how to purchase the information in database and other formats.

    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).