Skip to content

MKReverseGeocoder not working?

June 21, 2010

I faced this problem,  when trying to reverse geocode with the location information I had and and my current location. So after googling I found that many of the developers faced the same problem and the problem goes this way. At some point in time mostly, right from the morning to around in the evening , the google server  does not respond to the requests that go from our apps, for whatever reasons that Apple and Google knows. Is there any alternative? Yes.

you can use the Google ‘s Reverse Geocode API’s to achieve the same what MKReverseGeoCoder does. But we will have to write the webservice functionalities and take care of parsing.

Example :,-73.961452&sensor=true

webservice = [[ADCWebservice alloc] init];

NSArray *keys = [NSArray arrayWithObjects:@”latlng”, @”sensor”, nil];

NSString *latitudeLongitude = [NSString stringWithFormat:@”%f,%f”,mapView.userLocation.location.coordinate.latitude,mapView.userLocation.location.coordinate.longitude];

NSArray *objects = [NSArray arrayWithObjects:latitudeLongitude,@”true”, nil];

NSDictionary *params =  [NSDictionary dictionaryWithObjects:objects forKeys:keys];

[webservice makeAPICall:params];

I have used JSON data format. And my Webserice class interface and  implementation goes this way:


#import <Foundation/Foundation.h>


Protocol for updating the Label.


@protocol CustomWebServiceDelegate

– (void)setPlacemarkInfo:(NSDictionary*)dictionary;


@interface ADCWebservice : NSObject {

id <CustomWebServiceDelegate> delegate;

NSMutableData *receivedData;

id returnDataFromWebservice;

NSDictionary *returnValue;

bool isQuerying;


@property (nonatomic, retain)id delegate;

@property bool isQuerying;

@property (nonatomic, retain)  NSDictionary *returnValue;

@property (nonatomic, retain) NSMutableData *receivedData;

– (void)makeAPICall:(NSDictionary *)dict;



#import “ADCWebservice.h”

#import “ADCUtilities.h”

#import <JSON/JSON.h>

@implementation ADCWebservice

@synthesize receivedData,isQuerying,returnValue, delegate;

#define kReverseGeoCodingURL @”;

– (void)makeAPICall:(NSDictionary *)params{

NSString *url=@””;

BOOL firstKey=TRUE;

for (NSString *key in params)


NSString *value=[params objectForKey:key];

if (!firstKey) url=[url stringByAppendingString:@”&”];

url=[url stringByAppendingString:key];

url=[url stringByAppendingString:@”=”];

url=[url stringByAppendingString: [value stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ];



NSLog(@”URL Parameter:%@”,url);

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

NSData *postData = [url dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];

[request setURL:[NSURL URLWithString:kReverseGeoCodingURL]];

[request setHTTPMethod:@”POST”];

[request setValue:@”application/x-www-form-urlencoded” forHTTPHeaderField:@”content-type”];

[request setHTTPBody:postData];

/* create the NSMutableData instance that will hold the received data */

receivedData = [[NSMutableData alloc] initWithLength:0];

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request



[connection start];


– (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {

[receivedData setLength:0];


– (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {

[receivedData appendData:data];


– (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {

[ADCUtilities displayAlertView:[error localizedDescription]];


– (void)connectionDidFinishLoading:(NSURLConnection *)connection {

[connection release];

NSString *jsonString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];

if([@”” isEqual:jsonString] ||jsonString==nil){

returnValue =  nil;


else {

SBJSON *jsonParser = [SBJSON new];

returnValue= (NSDictionary*)[jsonParser objectWithString:jsonString];


[jsonString release];

[delegate setPlacemarkInfo:returnValue];


– (void)dealloc {

[receivedData release];

[returnValue release];

[super dealloc];




From → iPhone

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: