FBAnnotationClustering 以编程方式显示注释

FBAnnotationClustering Show Annotation Programmatically

我在我的项目中使用 FBAnnotationClustering。我在以编程方式显示注释视图时遇到了困难..

例如。 当捕捉到 MapView 上的图钉时,我们希望显示注释。

我查看了代码,似乎无法找到触发 "show annotation" 类型函数的位置。

mapView selectAnnotation 的简单答案无效,因为未使用地图设置注释并且出现 "ERROR: You are trying to select an annotation that has yet been added to the map"....

有什么想法吗?

FBAnnotationClustering 的开发人员在 GitHub 上用以下答案回答了我的问题。

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    if ([view.annotation isKindOfClass:[FBAnnotationCluster class]]) {
        FBAnnotationCluster *cluster = (FBAnnotationCluster *)view.annotation;

        int i = 0;
        MKMapPoint points[cluster.annotations.count];

        for (id<MKAnnotation> annotation in cluster.annotations){
            points[i++] = MKMapPointForCoordinate(annotation.coordinate);
        }

        MKPolygon *polygon = [MKPolygon polygonWithPoints:points count:i];
        MKMapRect newMapRect = [polygon boundingMapRect];

        [mapView setVisibleMapRect:newMapRect edgePadding:UIEdgeInsetsMake(50, 50, 50, 50) animated:YES];
    }
}

GitHub 问题已经结束 here