Search code examples
iphoneiosobjective-cios5mapkit

Get coordinate from zip code (postal code) or city/state


Im using Map Kit and Core Location now and need to to get location information from zip code or city/state. Is there any way to do it?


Solution

  • You can use the CLGeocoder class which supports converting an address to a coordinate, and the reverse. For example:

    [geocoder geocodeAddressString:@"<postcode here>"
                 completionHandler:^(NSArray* placemarks, NSError* error){
                     for (CLPlacemark* aPlacemark in placemarks)
                     {
                         // Process the placemark.
                     }
    }];
    

    There are a bunch of different methods you may want to use. You can limit the search to a particular region, for example.