CLGeocoderに非常に失望した後、代わりにGoogleMapsAPIを使用することにしました。
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];
私はこのフィードバックを受け取ります:
結果を取得:'(null)'(null)エラーなし{"Cache-Control" = "public、max-age = 86400"; "Content-Encoding" = gzip; "Content-Length" = 1603; "Content-Type" = "application / json; charset = UTF-8"; 日付="2012年12月7日金曜日08:51:58GMT"; Expires="2012年12月8日土曜日08:51:58GMT"; サーバー=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
結果はヌルですが、エラーはありません。コンテンツはヘッダーでJSONとして認識されますが、生のJSONはnullです。
厄介なのは、ブラウザでhttp://maps.googleapis.com/maps/api/geocode/json?sensor=true&address=thorsgadeを開くと、たくさんの結果が得られることです。
これまで私は試しました:
- センサーブールオンの真/偽をフリックします。
- ユーザーエージェントを通常のサファリに偽造する。
- GETの代わりにPOSTを使用してください。
運がない...