【问题标题】:Forward Geocoding with CLGeocoder Issues带有 CLGeocoder 问题的正向地理编码
【发布时间】:2012-02-09 09:46:33
【问题描述】:

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

我有一个 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;
}

任何建议将不胜感激。

【问题讨论】:

    标签: iphone ios ios5 mkmapview clgeocoder


    【解决方案1】:

    如果是内存问题,你有没有考虑过注解是如何出队和重用的,地图视图有一个委托方法来做这样的事情。

    本教程可能会有所帮助。

    Ray Wenderlich map tutorial

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-02
      • 2012-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多