I was wondering if it was possible to get the state abbreviations from CLPlacemark?
In the CLPlacemark Reference from Apple it states:
administrativeArea The sta
I think you can't get the abbreviations of the states but you can make your own class for this..
Code..
Class StateAbbreviation
StateAbbreviation.h
@interface StateAbbreviation : NSString {
}
+ (NSString *)allStates:(int)index;
+ (NSString *)abbreviatedState:(NSString *)strState;
@end
StateAbbreviation.m
@implementation StateAbbreviation
+ (NSString *)allStates:(NSString *)strState {
// Remove all space on the string
strState = [strState stringByReplacingOccurrencesOfString:@" " withString:@""];
//Sample states
NSArray *states = [[NSArray alloc] initWithObjects:
@"ALABAMA",
@"ALASKA", //AK
@"AMERICANSAMOA", //AS
@"ARIZONA", //AZ
@"ARKANSAS", //AR
@"CALIFORNIA", //CA
nil];
NSUInteger n = [states indexOfObject:strState];
if (n > [states count] - 1) {
strAbbreviation = @"NOSTATE";
}
else {
strAbbreviation =[self abbreviatedState:n];
}
[states release];
return strAbbreviation;
}
+ (NSString *)abbreviatedState:(int)index {
NSArray *states = [[NSArray alloc] initWithObjects:
@"AL",
@"AK",
@"AS",
@"AZ",
@"AR",
@"CA",
nil];
NSString *strAbbreviation = [states objectAtIndex:index];
[states release];
return strAbbreviation;
}
@end
When you call the class it should be something like this
NSString *upperCase = [@"California" uppercaseString]; // California could be from (NSString *)placemark.administrativeArea;
NSString *abbr = [StateAbbreviation allStates:upperCase];
NSLog(@"%@", abbr); // Result should be CA
This are only samples you can research all states something like this, states and their abbreviations also like this states and their abbreviations