2

iOS5 で geocodeAddressString 関数を使用してフォワード ジオコーディングを使用すると問題が発生します。

インターネットから取得したデータを使用してさまざまな場所を表示するために、MKMapView をモーダル ビューとして開いています。私の問題は、モーダル ビューを閉じてから再度開いたときです。2 回目の試行では、注釈の約半分だけが実際にマップに配置されています。3 回目の試行では、何も表示されません。

ここでの問題は、メモリ管理と CLGeocoder の範囲に関係しているように感じますが、それを理解することはできません。

MapView を含むビュー コントローラーの ViewDidLoad 関数ですべての注釈を作成します。アドレスの座標を取得するために使用するコードは次のとおりです。

int locationCount = 0;
for(NSDictionary *date in locations)
{
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressString:[NSString stringWithFormat:@"%@, %@", [date objectForKey:@"venue"], [date objectForKey:@"location"]] completionHandler:^(NSArray *placemarks, NSError *error)
    {
        // if we find the exact location (including the venue string), create an annotation for the map
        if(placemarks && placemarks.count > 0)
        {
            CLPlacemark *topResult = [placemarks objectAtIndex:0];
            TourAnnotation *placemarkAnnotation = [[TourAnnotation alloc] initWithLocation:topResult.location andDetails:date];
            placemarkAnnotation.tag = locationCount;
            [tourMap addAnnotation:placemarkAnnotation];
        }
        // if not place an annotation at the center of the city
        else
        {
            [geocoder geocodeAddressString:[date objectForKey:@"location"] completionHandler:^(NSArray *placemarks, NSError *error)
             {
                 if(placemarks && placemarks.count > 0)
                 {
                     CLPlacemark *topResult = [placemarks objectAtIndex:0];
                     TourAnnotation *placemarkAnnotation = [[TourAnnotation alloc] initWithLocation:topResult.location andDetails:date];
                     placemarkAnnotation.tag = locationCount;
                     [tourMap addAnnotation:placemarkAnnotation];
                 }
             }];
        }
    }];
    ++locationCount;
}

任意の提案をいただければ幸いです。

4

1 に答える 1