i have many annotations on my map, How can i grouping Annotation Pins on the Same Coordinate?, i found this but i down't know how can i use that
Asked
Active
Viewed 895 times
0
-
See http://stackoverflow.com/a/17711620/1271826. Bottom line, [WWDC 2011 #111 - Visualizing Information Geographically with MapKit](https://developer.apple.com/videos/wwdc/2011/?id=111) video illustrates one nice approach (including some decent animations as you zoom in and out). – Rob Dec 18 '14 at 16:38
2 Answers
0
I think do you mean use something like a cluster on your map for grouping the pins, isn't it? I used sometime REVClusterMap: https://github.com/RVLVR/REVClusterMap
Is very useful to avoid to show many points on the map. With that, you show groups of annotations (the clusters) when you are far on the map, and when you zoom in, the points are appearing.
You only have to define your map like this:
REVClusterMapView *mapView;
mapView = [[REVClusterMapView alloc] initWithFrame:viewBounds];
And when you have to add and define the annotations, it will be like this:
NSMutableArray *pins = [NSMutableArray array];
for(int i=0;i<50;i++) {
...
CLLocationCoordinate2D newCoord = {lat+latDelta, lng+lonDelta};
REVClusterPin *pin = [[REVClusterPin alloc] init];
pin.title = [NSString stringWithFormat:@"Pin %i",i+1];;
pin.subtitle = [NSString stringWithFormat:@"Pin %i subtitle",i+1];
pin.coordinate = newCoord;
[pins addObject:pin];
[pin release];
}
[mapView addAnnotations:pins];
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation {
...
REVClusterPin *pin = (REVClusterPin *)annotation;
MKAnnotationView *annView;
if( [pin nodeCount] > 0 ) { //cluster
pin.title = @"___";
annView = (REVClusterAnnotationView*)
[mapView dequeueReusableAnnotationViewWithIdentifier:@"cluster"];
if( !annView )
annView = (REVClusterAnnotationView*)
[[REVClusterAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:@"cluster"];
annView.image = [UIImage imageNamed:@"cluster.png"];
[(REVClusterAnnotationView*)annView setClusterText:
[NSString stringWithFormat:@"%i",[pin nodeCount]]];
annView.canShowCallout = NO;
}
else { //show your code for a single annotation
...
}
I hope it will be useful :)

Thais
- 128
- 7
-
-
@HelloWorld is not working? Do you try the example on github? Maybe could be some updates on the library, maybe it will be better if you take a look at the example to see if this is what you wanna do. Anyway, what problem do you have? the cluster doesn't appear on the map? the annotations appear like always? do you add the cluster image to the code, isn't it? – Thais Dec 19 '14 at 10:10
-
Yes, I did all the steps, but i just have single annotations on my mapview – HelloWorld Dec 19 '14 at 14:42