gpt4 book ai didi

iphone - 带有 CLGeocoder 问题的正向地理编码

转载 作者:行者123 更新时间:2023-12-01 16:59:06 25 4
gpt4 key购买 nike

我在 iOS5 上使用 geocodeAddressString 函数使用前向地理编码时遇到问题。

我有一个 MKMapView 作为模态视图打开,以显示不同的位置以及从互联网上获取的数据。我的问题是当我关闭模态视图,然后再次打开它时。第二次尝试时,实际上只有大约一半的注释被放置在 map 上。在第三次尝试时,没有出现。

我觉得我的问题与内存管理和 CLGeocoder 的范围有关,但我就是想不通。

我在包含 MapView 的 View Controller 的 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;
}

任何建议,将不胜感激。

最佳答案

如果是内存问题,您是否考虑过注释是如何出队和重用的, map View 有一个委托(delegate)方法来做这样的事情。

本教程可能会有所帮助。

Ray Wenderlich map tutorial

关于iphone - 带有 CLGeocoder 问题的正向地理编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8846350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com