After the very disappointment of CLGeocoder, I decided to use the GoogleMaps API instead.
I designed the call as follows: 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 the result: '(null)' (null) due to the error {"Cache-Control" = "public, max-age = 86400"; "Content-Encoding" = gzip; "Content-Length" = 1603; "Content-Type" = "application / json; charset = UTF-8"; Date = "Fri, Dec 07, 2012 08:51:58 GMT"; Expires = "Sat, Dec 08, 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
Zero result, but no errors. The content is recognized in the headers as JSON, but the source JSON is null.
It’s annoying that if I open http://maps.googleapis.com/maps/api/geocode/json?sensor=true&address=thorsgade in the browser, I get a lot of results.
So far I have tried:
- Sensor flag booleon true / false.
- User agent fake for regular safari.
- Use POST instead of GET.
Bad luck...
source share