Geocoding on the iPhone: Getting the latitude and longitude of an address

I just started working on a project where I need to take an address and turn it in to a latitude/longitude pair. It turns out that this is called geocoding. When I was looking at the docs for MapKit I noticed that Apple conveniently provided some geocoding functionality. Unfortunately it only offers reverse geocoding (turning lat/long into an address). So I went over to the Google Maps API site and checked out what was available there. The call I was interested in looks like this:

http://maps.googleapis.com/maps/api/geocode/json?
address=ADDRESS_GOES_HERE&sensor=TRUE_OR_FALSE

It gives you back a nice big JSON response with lots of information about the address, including the latitude and longitude. So I made a nice simple Geocoder class to get that information.

My Geocoder object just grabs the lat/long and builds up an MKCoordinateRegion to send back to the GeocoderDelegate. The sample app shows how to use Geocoder to adjust a MKMapView.

//
//  Geocoder.h
//
//  Created by Randall Brown on 3/14/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@protocol GeocoderDelegate

-(void)locationFoundWithMapRegion:(MKCoordinateRegion)region;

@end

@interface Geocoder : NSObject
{
	id<GeocoderDelegate> delegate;
	NSMutableData *receivedData;
}

-(void)getCoordinateForAddress:(NSString*)address;

@property (assign) id<GeocoderDelegate> delegate;

@end

Check it out on github.

This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Geocoding on the iPhone: Getting the latitude and longitude of an address

  1. Filmy onlinee says:

    Nowa strona oferujaca filmy Online http://filmy-online.com.pl filmy Nowa strona oferujaca filmy Online http://filmy-online.com.pl filmy Nowa strona oferujaca filmy Online http://filmy-online.com.pl filmy Nowa strona oferujaca filmy Online http://filmy-online.com.pl filmy Nowa strona oferujaca filmy Online http://filmy-online.com.pl filmy Nowa strona oferujaca filmy Online http://filmy-online.com.pl filmy Nowa strona oferujaca filmy Online http://filmy-online.com.pl filmy Nowa strona oferujaca filmy Online http://filmy-online.com.pl filmy

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>