我正在使用 MKMapView...我正在向 map 添加大量注释,这导致 map 移动缓慢。 我想显示/隐藏带有缩放级别的注释。在每次缩放中,我都想隐藏重叠的注释。 有什么解决办法吗?
到目前为止,我想出了重叠上的 comapring 注释边界矩形,如果有重叠,则删除注释。这个解决方案很慢,因为我需要将所有内容与所有内容进行比较(我知道,我可以使用树等...),其次,删除注释并将其添加回 map 的速度有点慢。
最好的办法是能够访问注解渲染,如果注解被渲染,检查它是否可以... 可以吗?
谢谢
最佳答案
你可以使用下面的代码
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
NSArray *annotations = [mapView annotations];
//NSLog(@"%@",annotations);
CustomAnnotation *annotation = nil;
for (int i=0; i<[annotations count]; i++) {
annotation = (CustomAnnotation*)[annotations objectAtIndex:i];
if (![annotation isKindOfClass:[MKUserLocation class]]) {
if (mapView.region.span.latitudeDelta <= 0.13f) {
[[mapView viewForAnnotation:annotation] setHidden:NO];
} else {
[[mapView viewForAnnotation:annotation] setHidden:YES];
}
}
}
}
您可以调整 if 条件中的 delta 以更舒适
关于objective-c - MKMapView 和注释隐藏缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12198390/