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?
British Dictionary definitions for Prov (1 of 2) province.
Country Code CA Country code according to ISO-3166 Alpha-2 CA is the two-letter country abbreviation for Canada.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With