Chapter 5. Geocoding

If you were developing on a platform that didn’t support geocoding, you’d need to make use of one of the many web services that provide geocoding (see later in this chapter for one such service). However, with the arrival of iOS 5, Apple has provided native support for both forward and reverse geocoding.

Note

Although reverse geocoding was provided in the Map Kit framework by the now deprecated MKReverseGeocoder class, before the arrival of iOS 5, there was no forward geocoding capabilities offered natively by the SDK. With the introduction of the CLGeocoder class, part of the Core Location framework, both capabilities are now natively provided. The CLGeocoder class should be used for all new application development.

Reverse Geocoding

Warning

Both forward and reverse geocoding requests make a network connection back to web services hosted by Apple. The calls will fail without a network connection.

Reverse geocoding is the process of converting coordinates (latitude and longitude) into place name information. From iOS 5 you should use the CLGeocoder class to make reverse-geocoding requests by passing it a CLLocation object.

CLLocation *location =
    [[CLLocation alloc] initWithLatitude:37.323 longitude:-122.031];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];

[geocoder reverseGeocodeLocation: location
    completionHandler: ^(NSArray *placemarks, NSError *error) {1

        for (

Get Geolocation in iOS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.