I'm using the MKPlacemark Class to populate a label with location specifics. When calling the AdministrativeArea property, the entire name of the US State is returned(ie West Virginia). Is there a way to return ONLY the initials(ie WV)?
Thanks.
I'm using the MKPlacemark Class to populate a label with location specifics. When calling the AdministrativeArea property, the entire name of the US State is returned(ie West Virginia). Is there a way to return ONLY the initials(ie WV)?
Thanks.
Apple's docs for that property suggest that there's no real definition for what it can contain. Your best bet is probably to create a function to map from the full state name to the 2 letter code, and pass the result of the property through it before display. I would default to the original string if you don't get a match.
-(NSString *)codeFromState:(NSString *)state {
NSArray *map = [NSArray arrayWithObjects:@"Alabama",@"AL", @"Alaska",@"AK", ... @"Wyoming", @"WY", nil];
for (int i = 0; i <[map count]; i+=2) {
if ([state compare:[map objectAtIndex:i]] == NSOrderedSame) {
return [map objectAtIndex:i+1];
}
}
return state;
}