From e9909f7ddd47577126713178b6f90fa7886df3ec Mon Sep 17 00:00:00 2001 From: Charles Niaulin Date: Tue, 24 Jul 2012 18:36:30 +0200 Subject: [PATCH] center cluster coordinate according to clustered pins --- OCMapView/OCAnnotation.m | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/OCMapView/OCAnnotation.m b/OCMapView/OCAnnotation.m index 98b8a12..d501450 100644 --- a/OCMapView/OCAnnotation.m +++ b/OCMapView/OCAnnotation.m @@ -65,6 +65,11 @@ - (NSArray *)annotationsInCluster{ - (void)addAnnotation:(id < MKAnnotation >)annotation{ [annotation retain]; + //calculate new cluster coordinate + float annotationCount = (float)[annotationsInCluster count]; + coordinate.latitude = (coordinate.latitude * annotationCount + annotation.coordinate.latitude) / (annotationCount + 1); + coordinate.longitude = (coordinate.longitude * annotationCount + annotation.coordinate.longitude) / (annotationCount + 1); + // Add annotation to the cluster [annotationsInCluster addObject:annotation]; [annotation release]; @@ -81,6 +86,11 @@ - (void)addAnnotations:(NSArray *)annotations{ - (void)removeAnnotation:(id < MKAnnotation >)annotation{ [annotation retain]; + //calculate new cluster coordinate + float annotationCount = (float)[annotationsInCluster count]; + coordinate.latitude = (coordinate.latitude * annotationCount - annotation.coordinate.latitude) / (annotationCount - 1); + coordinate.longitude = (coordinate.longitude * annotationCount - annotation.coordinate.longitude) / (annotationCount - 1); + // Remove annotation from cluster [annotationsInCluster removeObject:annotation];