2012-01-13 47 views
2

我在使用geocodeAddressString函數的iOS5上使用前向地理編碼時遇到問題。使用CLGeocoder轉發地理編碼問題

我有一個MKMapView作爲模態視圖打開,顯示從互聯網抓取的數據的不同位置。我的問題是當我解散模態視圖,然後再打開它。第二次嘗試時,我的註釋中只有大約一半實際放置在地圖上。第三次嘗試,沒有出現。

我有一種感覺,我的問題在這裏與內存管理和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; 
} 

任何意見,將不勝感激。

回答

0

如果是內存問題,您是否考慮過註釋如何出列和重用,地圖視圖具有一個委託方法來執行此類操作。

本教程可能會有一些幫助。

Ray Wenderlich map tutorial