I have built a Map application that uses the Kingpin map pin clustering library, (found here) at present the library succeeds in approximating the position of the pins and placing the cluster pin. However, the original pins are never removed as seen here. I think the relevant code is this:
-(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:@"icon_notif_recall.png"];
annotationView.frame=CGRectMake(0,0,25,25);
}
}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:@"icon_notif_recall.png"];
annotationView.frame=CGRectMake(0,0,25,25);
}
}
return annotationView;
}else if([annotation isKindOfClass:[REC_CustomAnnotation class]]){//Check that is our custom pin class
REC_CustomAnnotation *myLocation = (REC_CustomAnnotation *)annotation;
MKAnnotationView *annotationView=[mapView dequeueReusableAnnotationViewWithIdentifier:@"REC_CustomAnnotation"];
if(annotationView==nil){
annotationView=myLocation.annotationView;
}else{
annotationView.annotation=annotation;
}
return annotationView;
}else{
return annotationView;
}
}
but I am really not sure what is wrong. Any thoughts on what the problem is or things to try would be greatly appreciated.
As it turned out, the function posted above was in fact the problem. However, I was on the complete wrong track in terms of understanding how kingpin worked. Got everything working with this:
}
I hope this ends up helping someone in the future.