12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- #import "CCHNearCenterMapClusterer.h"
- #import <float.h>
- @implementation CCHNearCenterMapClusterer
- id<MKAnnotation> findClosestAnnotation(NSSet *annotations, MKMapPoint mapPoint)
- {
- id<MKAnnotation> closestAnnotation;
- CLLocationDistance closestDistance = __DBL_MAX__;
- for (id<MKAnnotation> annotation in annotations) {
- MKMapPoint annotationAsMapPoint = MKMapPointForCoordinate(annotation.coordinate);
- CLLocationDistance distance = MKMetersBetweenMapPoints(mapPoint, annotationAsMapPoint);
- if (distance < closestDistance) {
- closestDistance = distance;
- closestAnnotation = annotation;
- }
- }
-
- return closestAnnotation;
- }
- - (CLLocationCoordinate2D)mapClusterController:(CCHMapClusterController *)mapClusterController coordinateForAnnotations:(NSSet *)annotations inMapRect:(MKMapRect)mapRect
- {
- MKMapPoint centerMapPoint = MKMapPointMake(MKMapRectGetMidX(mapRect), MKMapRectGetMidY(mapRect));
- id<MKAnnotation> closestAnnotation = findClosestAnnotation(annotations, centerMapPoint);
- return closestAnnotation.coordinate;
- }
- @end
|