iOS:缩小地图时应用程序崩溃 [英] iOS : App crashes when zooming out a map
问题描述
在这种情况下,缩小地图会导致我的应用崩溃.
I have this situation where my app crashes when I zoom out the map.
由于我要添加大量注释,所以出现了问题.请在下面查看我的代码:
The problem arises because of the large number of annotations that I'm adding. Please have a look at my code below :
- (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多个引脚,这些引脚我认为是导致崩溃的原因[可能是内存泄漏!].我想知道在缩小时是否可以一一添加针脚吗?
Here I'm trying to add more than 400 pins which I think is the cause of crash [probably a memory leak!]. I would like to know if there is any way to add the pins one by one as I zoom out?
地图处于初始阶段,没有任何问题:
Map in initial stage, without any problem :
当我缩小时:
推荐答案
尝试集群.基本上,您将注释分组在一起.
Try clustering. Basically you group together annotations.
我链接到的文章中的代码回购: https://github.com/applidium/ADClusterMapView
The code repo from the article I linked to: https://github.com/applidium/ADClusterMapView
这篇关于iOS:缩小地图时应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!