【发布时间】:2012-12-07 08:54:02
【问题描述】:
在对 CLGeocoder 非常失望后,我决定改用 GoogleMaps API。
我使用 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) from no error { “缓存控制”=“公共,最大年龄=86400”; “内容编码”= gzip; “内容长度”= 1603; “内容类型”=“应用程序/json;字符集=UTF-8”; 日期 =“格林威治标准时间 2012 年 12 月 7 日星期五 08:51:58”; 过期 =“星期六,2012 年 12 月 8 日 08:51:58 GMT”; 服务器 = mafe; Vary = "接受语言"; “X-Frame-Options”=SAMEORIGIN; “X-XSS-保护”=“1;模式=块”; } http://maps.googleapis.com/maps/api/geocode/json?sensor=true&address=thorsgade
空结果,但没有错误。内容在标头中被识别为 JSON,但原始 JSON 为空。
烦人的是,如果我在浏览器中打开http://maps.googleapis.com/maps/api/geocode/json?sensor=true&address=thorsgade,我会得到很多结果。
到目前为止我已经尝试过:
- 滑动传感器布尔值真/假。
- 将用户代理伪装成常规的 safari。
- 使用 POST 而不是 GET。
没有运气......
【问题讨论】:
-
它对我来说很好用 :),你检查的是哪个 iOS 版本?
-
我正在检查 6.0 和 6.0.1
标签: iphone objective-c google-api geocoding afnetworking