Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 208
Devin Crossman Avatar asked Jul 03 '12 19:07

Devin Crossman


People also ask

What is the abbreviation of province?

British Dictionary definitions for Prov (1 of 2) province.

What is Canada's 2 letter abbreviation?

Country Code CA Country code according to ISO-3166 Alpha-2 CA is the two-letter country abbreviation for Canada.


1 Answers

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.

like image 112
Matt Avatar answered Sep 27 '22 21:09

Matt