Reverse Geocoding for iOS using the API

In this tutorial, we'll be creating a simple iPhone app capable of reverse geocoding - the process of finding the nearest address from a set of location coordinates. In this case, our location coordinates represent the user's current location and will be provided natively by the CoreLocation framework (more on this in a bit).

On route we'll learn how to make requests to a web service using NSURLConnection and how to process the JSON response we get back from it, using SBJson (a JSON parsing framework) which is available at

Open Xcode (I'm using version 4.2 but instructions shouldn't vary too much for earlier/later versions) and create a new Xcode project. Choose Single View Application as the template for your new project and name your product something appropriate. Leave the 3 checkboxes unchecked and click next and then create in the following dialog.

Grab the Frameworks etc

(Note: There are more detailed instructions on the respective github pages telling you how to successfully get the frameworks into Xcode if you get stuck with either of these steps).

Head over to and download the latest .ZIP file. Open up the .ZIP and select all the files in the Classes folder then drag them into your project, creating a new group for them to keep things tidy.

We're also going to use a lovely, easy to use, loading indicator which you can find at Create another new group and drag the MBProgressHUD.h and MBProgressHUD.m files into it.

Lastly - We need to add the CoreLocation framework to our project. In the project navigator, select your project - Select your target and then the 'Build Phases' tab. Open the 'Link Binaries with Libraries' expander and click the '+' button. Search for the CoreLocation framework and click 'Add'.

The User Interface

Open up your .xib file and drag on a Label and a button, then open up your view controller's header file and add an IBOutlet for your label and an IBAction for your button.

@interface ViewController : UIViewController {

UILabel *addressLabel;


@property (nonatomic, retain) IBOutlet UILabel *addressLabel;

-(IBAction) buttonClick;


Go back to the Interface Builder for your .xib file, right click the File's Owner icon (the semi-transparent yellow box to the left of the editing area). Drag the addressLabel outlet onto your label and the buttonClick received action onto your button, selecting touch up inside as the type of interaction.

Back to the Header File

We need to add a few things in our header file before we can get on with coding the beefy bits of our application. Shortly but sweetly:

  • Import the CoreLocation and MBProgressHUD.h header files.
  • Have your view controller implement the CLLocationManagerDelegate delegate.
  • Add instance variables for responseData (NSMutableData), locationManager (CLLocationManager), currentLat (CLLocationDegrees), currentLon (CLLocationDegrees) and HUD (MBProgressHUD).

Your finished header file should look like this:

#import ;
#import ;
#import "MBProgressHUD.h"

@interface ViewController : UIViewController  {

NSMutableData *responseData;

CLLocationManager *locationManager;

CLLocationDegrees currentLat;

CLLocationDegrees currentLon;

UILabel *addressLabel;

MBProgressHUD *HUD;


@property (nonatomic, retain) IBOutlet UILabel *addressLabel;

-(IBAction) buttonClick;


The Beef Of The Code

Include the SBJson.h header file in your implementation file, and synthesize the addressLabel property we created earlier.