Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8967841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:20:08+00:00 2026-06-15T17:20:08+00:00

After being very disappointed with CLGeocoder, I decided to use the GoogleMaps API instead.

  • 0

After being very disappointed with CLGeocoder, I decided to use the GoogleMaps API instead.

I have designed the call as following, using AFNetwork :

    AFHTTPClient *new = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://maps.googleapis.com/"]];

    NSDictionary *dict = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:@"thorsgade",@"true", nil] forKeys:[NSArray arrayWithObjects:@"address",@"sensor", nil]];
    NSMutableURLRequest *req = [new requestWithMethod:@"GET" path:@"maps/api/geocode/json" parameters:dict];

AFJSONRequestOperation *call = [AFJSONRequestOperation JSONRequestOperationWithRequest:req success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
            NSArray *geos = [JSON objectForKey:@"results"];
  DLog(@"Got result : '%@' %@ from  %@ %@ %@",JSON,geos,[NSHTTPURLResponse localizedStringForStatusCode:response.statusCode],response.allHeaderFields,request.URL.description);

        } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
            DLog(@"Failed %@ %@",error.localizedDescription,request.URL.description);
        }];

[call start];

I get this feedback:

Got result : ‘(null)’ (null) from no error {
“Cache-Control” = “public, max-age=86400”;
“Content-Encoding” = gzip;
“Content-Length” = 1603;
“Content-Type” = “application/json; charset=UTF-8”;
Date = “Fri, 07 Dec 2012 08:51:58 GMT”;
Expires = “Sat, 08 Dec 2012 08:51:58 GMT”;
Server = mafe;
Vary = “Accept-Language”;
“X-Frame-Options” = SAMEORIGIN;
“X-XSS-Protection” = “1; mode=block”; } http://maps.googleapis.com/maps/api/geocode/json?sensor=true&address=thorsgade

Null result, but no errors. The content is recognized in the headers as JSON, but the raw JSON is null.

The annoying thing is that if I open http://maps.googleapis.com/maps/api/geocode/json?sensor=true&address=thorsgade in a browser, i get plenty of results.

So far i have tried:

  • Flicking the sensor booleon true/false.
  • Faking the user-agent to be regular safari.
  • Use POST instead of GET.

With no luck…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:20:09+00:00Added an answer on June 15, 2026 at 5:20 pm

    If the problem persists, I would recommend using MKNetworkKit instead

    Here is my solution –

    GoogleGeocodeApi.h

    //GoogleGeocodeApi.h
    #import <Foundation/Foundation.h>
    #import "MKNetworkEngine.h"
    
    typedef void (^JsonResponseBlock)(NSDictionary *);
    typedef void (^ErrorBlock)(NSError* error);
    
    @interface GoogleGeocodeApi : MKNetworkEngine
    
    -(MKNetworkOperation*) geocodeWithAddress: (NSString *) address
                                 onCompletion:(JsonResponseBlock) completionBlock
                                      onError:(ErrorBlock) errorBlock;
    
    @end
    

    GoogleGeocodeApi.m

    //GoogleGeocodeApi.m
    #import "GoogleGeocodeApi.h"
    
    @implementation GoogleGeocodeApi
    
    -(id)init
    {
        if (self = [super initWithHostName:@"maps.googleapis.com" apiPath:@"maps/api/geocode" customHeaderFields:nil]) {
    
        }
        return self;
    }
    
    -(MKNetworkOperation*) geocodeWithAddress: (NSString *) address
                                 onCompletion:(JsonResponseBlock) completionBlock
                                      onError:(ErrorBlock) errorBlock;
    {
        MKNetworkOperation *op = [self operationWithPath:[NSString stringWithFormat:@"json?sensor=true&address=%@", address] params:nil httpMethod:@"GET"];
        [op onCompletion:^(MKNetworkOperation *completedOperation) {
            NSDictionary *responseJSON = [completedOperation responseJSON];
            if (responseJSON && [[responseJSON objectForKey:@"status"] isEqualToString:@"OK"]) {
                completionBlock(responseJSON);
            } else {
                NSDictionary* errorDictionary = @{NSLocalizedDescriptionKey :@"Google geocode failed!"};
                NSError *error = [NSError errorWithDomain:@"Failed response" code:100 userInfo:errorDictionary];
                errorBlock(error);
            }
        } onError:^(NSError* error) {
            errorBlock(error);
        }];
    
        [self enqueueOperation:op];
    
        return op;
    }
    

    Somewhere in code

    GoogleGeocodeApi *gma = [[GoogleGeocodeApi alloc] init];
    
        [gma geocodeWithAddress:@"thorsgade"
                   onCompletion:^(NSDictionary *responseJSON) {
                       NSLog(@"Geocode succeeded: %@", responseJSON);
                   } onError:^(NSError *error) {
                       NSLog(@"Geocode failed with error: %@", [error localizedDescription]);
                   }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented the following set up (after being requested): slideshow of images changing,
After being pointed to using glBitmap() and this very good tutorial/explanation of its usage
Recently, after being very tired, I wrote the following code: GLfloat* array = new
I have a situation where a Java Applet hangs after being opened multiple times.
What I am after is being able to have my application, in dev mode,
We have an ongoing problem with message writes to MSMQ being very slow. Our
I'm using the LUA middleclass library now after some problems and I have a
I've just learned the basics of Ruby after being very happy with Python for
After being stumped by an earlier quesiton: SO google-analytics-domain-data-without-filtering I've been experimenting with a
After being blown away by the greatness of irb and rails console, I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.