在對CLGeocoder非常失望之後,我決定改用GoogleMaps API。AFNetwork和GoogleAPI返回NULL
我已經設計了通話如下,使用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];
我得到這樣的反饋:
得到的結果:從沒有錯誤(空)(空){ 「 Cache-Control「=」public,max-age = 86400「; 「內容編碼」= gzip; 「Content-Length」= 1603; 「Content-Type」=「application/json; charset = UTF-8」; 日期=「星期五,2012年12月07日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
無結果,但沒有錯誤。內容在標頭中被識別爲JSON,但原始的JSON爲空。
令人討厭的是,如果我在瀏覽器中打開http://maps.googleapis.com/maps/api/geocode/json?sensor=true&address=thorsgade,我會得到很多結果。
到目前爲止,我曾嘗試:
- 輕彈傳感器booleon真/假。
- 將用戶代理僞裝成常規Safari。
- 使用POST而不是GET。
,沒有運氣...
它的正常工作對我來說:),你檢查哪個IOS版本? – aahsanali
即時檢查6.0和6.0.1 –