4

I'm using Swift to do a reverse geocode on a device's location, getting the country. Then finding the index of that country in an array and scrolling to that index in my UITableView.

My problem is, I can't find a list of the country names Apple would return.

For example, my UITableView might have a row with the title "United States of America", but the country returned by Apple's API is "United States". My UITableView then obviously doesn't scroll to that position.

I've thought of running through the array and doing a type of contains() to see if the country returned by Apple is somewhere within the array element but this seems like a pretty nasty way around both for performance and the fact that it will only solve SOME instances of the problem.

Gabriel Tomitsuka
  • 1,121
  • 10
  • 24
Byron Coetsee
  • 3,533
  • 5
  • 20
  • 31
  • Hmm... Interesting. I haven't looked into it properly but I imagine that they would use some sort of standard country code as well as the name. Is that a possibility? – Fogmeister Dec 17 '14 at 21:15
  • I found something where a guy used a python script to convert standard country codes into country names. Codes seem to be standard across the board, but even the names returned by pythons libraries are different and I haven't yet found anything identifying a specific standard of some sort :/ – Byron Coetsee Dec 17 '14 at 21:18
  • Use the codes. Not the names :-) if apple decides to change how it returns the name then it will break. But not if you're using he codes. – Fogmeister Dec 17 '14 at 21:21
  • You've tagged the question MKReverseGeocoder but since that was deprecated a long time ago, you must be using CLGeocoder instead? With CLGeocoder, the CLPlacemark has a ISOcountryCode property which is based on a standard. –  Dec 17 '14 at 21:25
  • Yes I am using CLGeocoder - not sure why I used MKReverseGeocoder... Ok I think I'm going to try link the codes to a list of some sort. I cant let the user select select their country code instead of country name - UX 101 :P – Byron Coetsee Dec 17 '14 at 21:29

1 Answers1

3

You can find the official list of ISO country codes (which are returned by a reverse geocode) here. It is the Alpha-2 code that gets returned.

Bagelman
  • 766
  • 8
  • 14
  • Although not exactly what i was looking for - was looking for a list of full country names geocode returns, ISO and alpha-2 codes are 2/3 letter codes) - i can still use this information. Thank you :) – Byron Coetsee Jan 12 '15 at 21:45
  • Does Apple use ```ISO 3166-1```, or do they use some other ISO version? I can't find out which version they support on their developer documentation site. – Supertecnoboff Oct 19 '18 at 12:16