6

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?

Devin Crossman
  • 7,454
  • 11
  • 64
  • 102

3 Answers3

2

In agreement with @user640118, state abbreviations don't change often, if ever, in North America. It would be best to just have a static listing of codes or abbreviations.

To answer your question, though, I've worked on one such web service called LiveAddress which provides geo/postal data via a simple REST endpoint. It's a bit more advanced, though, in the sense that it accepts an address, partial or complete, and fills it out completely and verifies it and standardizes it. You may find that to be valuable in removing duplicates and geocoding your users' data.

If you have an address, you can use this wrapper function like so, in Javascript:

LiveAddress.verify("123 main st 12345", function(results) {
   console.log(results);
});

Sample output can be found in the API docs.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Matt
  • 22,721
  • 17
  • 71
  • 112
1

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

user640118
  • 803
  • 2
  • 13
  • 25
1

Geonames provides 2 letter abbreviations for countries but only has them for states in a few countries.

Why they don't provide something as standard (and useful) as this is beyond me.

bitstream
  • 459
  • 9
  • 20