5

I want to create an "Add Address" view, a very basic "Street, City, Zip, Country" type of page: multiple text fields inside a table view. This is simple if you only ever added U.S addresses, but I'm not sure about how to do this the right way though, handling all international use-cases as well. Essentially: 1. How do you pick the right field label for each country? For e.g. for US / Australian addresses, the field should be called "State"; for UK, it's called "County", in some places it's called "Province". How do you know what the label should say (short of hard-coding logic myself for each country)? 2. How do you validate the values for those field? UK postal codes have a certain format, whereas in the US it's a 5-digit ZIP code. Also, in the US, there is a list of states that the user can select. How do you get that list?

I've looked into NSLocale, and can't find any way to do this. Surely there must be a good and easy way to do this?

Z S
  • 7,039
  • 12
  • 53
  • 105

2 Answers2

6

I dug around and in the end the best thing I found was a guide on "The good international address field form", but it'll still be hard to validate it. I don't think it's done.

http://www.uxmatters.com/mt/archives/2008/06/international-address-fields-in-web-forms.php

One method could be to reverse lookup the address through mapkit.

Theis Egeberg
  • 2,556
  • 21
  • 30
  • Thanks. This might be as close as it gets. I suppose a generic form (as recommended by this site) is the way to go, or one can put in the work and parse one of the links included from the article to figure out when to use State vs Province vs County. On the web, or on the Mac, it might be OK to label the field "State / Province / County", since you have the space for it. It might be appropriate on iOS, but I could put this inside as a placeholder text. Still not the solution I was hoping for, but maybe that was unnecessarily detailed. – Z S Mar 03 '14 at 20:16
  • Also, one can at least get a list of countries in the world using this: http://stackoverflow.com/a/502872/145552 – Z S Mar 03 '14 at 20:17
2

You can try to simplify the UI by adding just one text field and ask user to enter his address in an arbitrary way, and then use CLGeocoder class to convert the string to instance of CLPlacemark, which is a convenient container for such information as country, postal code, etc.

nalexn
  • 10,615
  • 6
  • 44
  • 48
  • Thanks, that's a good idea, but not what I'm looking for. I want to know how Apple does it in the Contacts app, or other apps do it in their implementation (including web apps that must go through the same situation). I want to display a proper form with all the correct fields, so that it looks more professional. – Z S Mar 03 '14 at 05:29
  • Well, since different counties have different naming convention for their administrative areas, it would be better for the UI for address to be presented incrementally, like a number of web services do. You can get a list of countries from somewhere, and ask user to pick the country at first, and then ask CLGeocoder to recognize the address of... the country. Since it returns an array of CLPlacemark, using this technique you can get the list of all administrative areas for the country, and so on, I think you got the idea. – nalexn Mar 03 '14 at 06:40
  • CLPlacemark isn't going to tell me, for e.g., if an address in Canada needs a "State" or a "Province" field, or whether the "Zip" field is actually called "Post-code". I agree that it's possible to have a free-form text field and let the user enter anything, then process it using CLGeocoder and CLPlacemark, but that's not the UI I am going for. I want the user to enter the address just as they do in the Contacts app. – Z S Mar 03 '14 at 07:06