我在使用geocodeAddressString函数在iOS5上使用正向地理编码时遇到问题。
我将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 :(得分:0)