Arpit B Parekh Arpit B Parekh -4 years ago 95
iOS Question

CLGeocoder: US state Names are coming as a short codes

I am developing app in iOS 8.0.

By below link, I am assigning the location object,
How can I get current location from user in iOS

My aim is to find out City, State and Country name, By current location.
Using answer of this link, I am getting the place mark objects used in Apple's Geocoder.
Get current city and country from CLGeocoder?

I am getting everything alright, just

When I am getting the state name for Country United States.
It gives me shortcodes, rather than giving me full state names.

e.g. For

it gives me

it gives me

Like this is my log,

North Kingstown, RI, United States

I want full state names, because I want to use full state name in my project.

I am getting state name by this code,

NSString *stateName=myPlacemark.administrativeArea;

Answer Source

As, I am only using Apple's GeoCoder. It is giving me only short codes of States of USA. e.g. CA for California.

I have used google but it is quite difficult to parse. The solution came from Wikipedia.

I have prepared below source to use the Full Name's from short codes.

NSArray *arrayShortCodes=[[NSArray alloc] initWithObjects:@"AL",@"AK",@"AZ",@"AR",@"CA",@"CO",@"CT",@"DE",@"DC",@"FL",@"GA",@"HI",@"ID",@"IL",@"IN",@"IA",@"KS",@"KY",@"LA",@"ME",@"MD",@"MA",@"MI",@"MN",@"MS",@"MO",@"MT",@"NE",@"NV",@"NH",@"NJ",@"NM",@"NY",@"NC",@"ND",@"OH",@"OK",@"OR",@"PA",@"RI",@"SC",@"SD",@"TN",@"TX",@"UT",@"VT",@"VA",@"WA",@"WV",@"WI",@"WY",nil];
    NSArray *arrayFullNames=[[NSArray alloc] initWithObjects:@"Alabama",@"Alaska",@"Arizona",@"Arkansas",@"California",@"Colorado",@"Connecticut",@"Delaware",@"District of Columbia",@"Florida",@"Georgia",@"Hawaii",@"Idaho",@"Illinois",@"Indiana",@"Iowa",@"Kansas",@"Kentucky",@"Louisiana",@"Maine",@"Maryland",@"Massachusetts",@"Michigan",@"Minnesota",@"Mississippi",@"Missouri",@"Montana",@"Nebraska",@"Nevada",@"New Hampshire",@"New Jersey",@"New Mexico",@"New York",@"North Carolina",@"North Dakota",@"Ohio",@"Oklahoma",@"Oregon",@"Pennsylvania",@"Rhode Island",@"South Carolina",@"South Dakota",@"Tennessee",@"Texas",@"Utah",@"Vermont",@"Virginia",@"Washington",@"West Virginia",@"Wisconsin",@"Wyoming", nil];

     dictionaryStateNames =[[NSDictionary alloc] initWithObjects:arrayFullNames forKeys:arrayShortCodes];

Now, we can easily access the fullname from short codes, using the valueForKey method of NSDictionary.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download