iOS:缩小地图时应用程序崩溃

时间:2014-03-19 18:54:07

标签: ios maps mkannotation

我遇到这种情况,当我缩小地图时我的应用程序崩溃了。

问题出现是因为我添加了大量注释。请看下面的代码:

- (void) plotUsersInMap
{
for (id<MKAnnotation> annotation in self.mapView.annotations) {
    [self.mapView removeAnnotation:annotation];
}

NSUInteger count = //get total count
NSLog(@"count * %d", count);
for (int i = 0; i < count; i++)
{
    NSNumber *latitude = //get latitude from json
    NSNumber *longitude = //get longitude from json

    CLLocationCoordinate2D coordinate;
    coordinate.latitude = latitude.doubleValue;
    coordinate.longitude = longitude.doubleValue;

    @autoreleasepool {

        MyLocation *annotation = [[MyLocation alloc] initWithName:@"test" coordinate:coordinate QuestionId:nil];
       //annotations are added
        [self.mapView addAnnotation:annotation];
    }
}
}

这里我试图添加超过400个引脚,我认为这是引起崩溃的原因[可能是内存泄漏!]。我想知道在缩小时是否有任何方法可以逐个添加引脚?

在初始阶段映射,没有任何问题: Initial stage

当我缩小时:

it crashes!!

1 个答案:

答案 0 :(得分:1)

试试clustering。基本上你把注释组合在一起。

我链接到https://github.com/applidium/ADClusterMapView

的文章中的代码回购
相关问题