处理 MKMapView 上的 MKAnnotations 时速度变慢
我正在逐步浏览地图上的注释,以便找到具有特定标签的注释。然后我删除这个注释,并添加一个新的注释(不同的颜色)。
问题是这需要非常非常长的时间。不知道为什么。它会处理 300 个注释,最多需要 20 秒!我怎样才能加快速度?例如,有没有办法只获取当前可见的注释?或者,如果我有注释,我可以告诉它在 mapView.annotations 数组中的索引是什么,这样我就不必单步执行吗?
for (int i =0; i < [self.mapView.annotations count]; i++)
{
if ([[self.mapView.annotations objectAtIndex:i] isKindOfClass:[BasicMapAnnotation class]] )
{
BasicMapAnnotation *bmaTemp =(BasicMapAnnotation*)[self.mapView.annotations objectAtIndex:i];
if (bmaTemp.mapTag == pinTag) {
[self.mapView removeAnnotation:[self.mapView.annotations objectAtIndex:i]];
self.customAnnotation = [[[BasicMapAnnotation alloc] initWithLatitude:[shop.latitude doubleValue] andLongitude:[shop.longitude doubleValue]] autorelease];
self.customAnnotation.mapTag = pinTag;
[self.mapView addAnnotation:self.customAnnotation];
}
}
}
I'm stepping thru the annotations on my map, in order to find one which has a certain tag. I then remove this annotation, and add a new one (a diff color)
The problem is that this takes a very, very long time. Not sure why. It's going thru 300 annotations, and it takes up to 20 seconds! How can I speed this up? It there a way to, for instance, only get the annotations which are currently visible? Or, if I have the annotation, can I tell what is its index in mapView.annotations array is, so I don't have to step thru?
for (int i =0; i < [self.mapView.annotations count]; i++)
{
if ([[self.mapView.annotations objectAtIndex:i] isKindOfClass:[BasicMapAnnotation class]] )
{
BasicMapAnnotation *bmaTemp =(BasicMapAnnotation*)[self.mapView.annotations objectAtIndex:i];
if (bmaTemp.mapTag == pinTag) {
[self.mapView removeAnnotation:[self.mapView.annotations objectAtIndex:i]];
self.customAnnotation = [[[BasicMapAnnotation alloc] initWithLatitude:[shop.latitude doubleValue] andLongitude:[shop.longitude doubleValue]] autorelease];
self.customAnnotation.mapTag = pinTag;
[self.mapView addAnnotation:self.customAnnotation];
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您确定要修改的注释实际上是可见的,您可以使用类似的内容
如果您想知道单个给定注释的索引:
未经测试,我在这里写了这个所以请让我知道它是否有效或不。
If you are sure that the Annotation you want to modify is actually visible, you could use something like
If you want to know the index of a single given annotation:
Untested, I wrote this here on SO so please let me know, whether it works or not.