Skip to content

Latest commit

 

History

History
71 lines (46 loc) · 2.91 KB

FAQ.md

File metadata and controls

71 lines (46 loc) · 2.91 KB

Kingpin FAQ

How to access cluster's annotations?

You can gain access to the cluster's annotations via -[KPAnnotation annotations].

How to disable clustering at a certain zoom level (multiple pins at same location)?

The simplest solution that worked for everyone so far:

Find category for MKMapView which provides you with zoom level (one example).

Then implement clustering controller's delegate method:

- (BOOL)clusteringControllerShouldClusterAnnotations:(KPClusteringController *)clusteringController {
    return self.mapView.zoomLevel < 14; // Find zoom level that suits your dataset
}

How to configure annotations with custom images?

Note: Notice that in the following example it is MKAnnotationView class that should be used as class or parent class for annotations with custom images, not the MKPinAnnotationView ! which is intended to work specifically with default annotation pin icons provided by Apple.

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {    
    MKAnnotationView *annotationView = nil;
    
    if ([annotation isKindOfClass:[KPAnnotation class]]) {
        KPAnnotation *kingpinAnnotation = (KPAnnotation *)annotation;
        
        if ([kingpinAnnotation isCluster]) { 
            annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"cluster"];
            
            if (annotationView == nil){
                annotationView = [[MKAnnotationView alloc] initWithAnnotation:kingpinAnnotation reuseIdentifier:@"cluster"];

                annotationView.canShowCallout = YES;

                annotationView.image = [UIImage imageNamed:@"blue"];
            }
        }

        else {
            annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pin"];
            
            if (annotationView == nil) {
                annotationView = [[MKAnnotationView alloc] initWithAnnotation:[kingpinAnnotation.annotations anyObject]
                                                              reuseIdentifier:@"pin"];

                annotationView.canShowCallout = YES;

                annotationView.image = [UIImage imageNamed:@"green"];
            }
        }
    }

    return annotationView;
}