O'Reilly logo

Geolocation in iOS by Alasdair Allan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 (

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required