3

I am wondering how I might be able to get the placemark's zip code in iOS. Any tips or suggestions will be deeply appreciated. Here is the code I have so far, I am able to get the city.

 - (void)recenterMapToPlacemark:(CLPlacemark *)placemark {
MKCoordinateRegion region;
MKCoordinateSpan span;

span.latitudeDelta = 0.02;
span.longitudeDelta = 0.02;

region.span = span;
region.center = placemark.location.coordinate;

NSString *city = [placemark locality];

 }
  • Have you tried something like this : NSString *zipCode = [placemark.addressDictionary objectForKey:(NSString*)kABPersonAddressZIPKey]; – userx Jan 13 '14 at 23:43
  • @AbhishekMukherjee You have a typo in your comment, you are missing a * sign after the NSString cast. However this isn't the right way to do it. Check the answer I posted. – Dominik Hadl Jan 13 '14 at 23:45
  • @DominikHadl It is not a NSString cast but a declaration. I typed the code at office. I hope the person asking the question got it working though. – userx Mar 13 '14 at 15:24
  • @AbhishekMukherjee I was referencing the `(NSString)kAB..` part, which is a cast and should be `(NSString *)kAB...`. But now as you write it, I've noticed you are also missing a `*` in the declaration (meaning `NSString zipCode` should be `NSString *zipCode`). – Dominik Hadl Mar 13 '14 at 17:29
  • @DominikHadl Thanks for pointing that out, but I already know that, it baffled me that even after saying I just typed the code in a non XCode environment, you still had to go through listing out missing *s.What was asked can also be achieved by kABPersonAddressZIPKey route. Not sure what prompted your comment of "not the right way to do it". – userx Mar 13 '14 at 19:48

1 Answers1

3

Check the documentation here: https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLPlacemark_class/Reference/Reference.html#//apple_ref/occ/instp/CLPlacemark/postalCode

It is the postalCode property you are looking for.
So in your case it is:

NSString *zipCode = placemark.postalCode;

Dominik Hadl
  • 3,609
  • 3
  • 24
  • 58