私はジオコーディングで位置情報を取得し、Googleマップビューに地図ピンを追加するために以下のコードを使用しています。このコードでは、Forループを使用してデータベースの各場所を循環します。問題は、実行時に場所の約50%の場所情報をコードが返さないことです。これらの失敗した項目は、以下のコードに従ってfailedLoad配列に保存されます。Googleジオコーディングを使用してForループ - 高いエラー率 - iPhone
これはどのような理由が考えられますか?また、これらの失敗したアイテムは "failedLoad"配列に保存されるので、この配列を使用して欠落しているピンをロードする方法はありますか?
EDIT
失敗したアイテムは、私があまりにも早く項目を提出していますことを意味620エラーに起因するものです。コードに遅延を追加するにはどうすればよいですか?
ありがとうございます!
-(void)displayPlaces {
for (PlaceObject *info in mapLocations) {
// GET ANNOTATION INFOS
NSString * addressOne = info.addressOne;
NSString * name = info.name;
NSString * postCode = info.postCode;
NSString * addressTwo = [addressOne stringByAppendingString:@",London,"];
NSString * address = [addressTwo stringByAppendingString:postCode];
NSString* urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURL* url = [NSURL URLWithString:urlString];
NSURLRequest* req = [NSURLRequest requestWithURL:url];
OHURLLoader* loader = [OHURLLoader URLLoaderWithRequest:req];
[loader startRequestWithCompletion:^(NSData* receivedData, NSInteger httpStatusCode) {
NSString* locationString = loader.receivedString;
NSArray *listItems = [locationString componentsSeparatedByString:@","];
double latitude = 0.0;
double longitude = 0.0;
if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {
latitude = [[listItems objectAtIndex:2] doubleValue];
longitude = [[listItems objectAtIndex:3] doubleValue];
}
else {
NSLog(@"Error %@",name);
[failedLoad addObject : info];
}
CLLocationCoordinate2D coordinate;
coordinate.latitude = latitude;
coordinate.longitude = longitude;
MyLocation *annotation = [[[MyLocation alloc] initWithName:name address:address coordinate:coordinate] autorelease];
[mapViewLink addAnnotation:annotation];
} errorHandler:^(NSError *error) {
NSLog(@"Error while downloading %@: %@",url,error);
}];
}
}
Google APIにはさまざまなクエリレートの制限があります。 1秒あたり最大10件のリクエスト。 APIを使用する予定がある場合は、実際にこのすべてをRTFMする必要があります。 –
場所が読み込まれない場合は、返された文字列をログに記録しないでください。なぜそれが失敗するのかはすぐに分かります。 – JeremyP
ありがとうございます - 私が理解している620エラーは、私が提出しているレートによるものです。私はどのようにしてコードを遅らせるのでしょうか? – GuybrushThreepwood