Multiple Annotations ( MKAnnotationView ) in the s

2020-07-10 05:41发布

问题:

Hi I am trying to implement Annotations grouping and animation if the user touch.

I did look a the different cluster Library solution but this wont work for my because I have multiple Annotations in the same Coordinates.

So this is what I want to do

1- I identify where there are multiple Annotations in the same place (Coordinates)? how can implement this ? find the annotations in the same coordinates and make a new group annotation ?

2- change the colour of that Annotation (to let the user know) I can do this on this method -(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation;

3- if the user touch the annotations in that group , annotations will move in a circle around their location.

So far I have all my annotation on the map some have a very dark shadow.

I want to focus in the first task now - grouping

I am not asking for code example I can do that I just need help figuring out what methods to use to implement the task .

Thanks for your help.

回答1:

I ended up implementing this code from StormID

Handling MKMapView Annotation Pins on the Same Coordinate

I have to make some changes but it works great.



回答2:

To get rid of the dark shadow, which is caused by stacked annotation views, I would change your mapView:viewForAnnotation: to recognize when the passed annotation has the same coordinates as another and only return a view (of a different color) for one of those annotations.

Then, for your animation, upon touch of the grouped annotation, I would set mapView.scrollEnabled = mapView.zoomEnabled = NO temporarily for simplicity's sake, hide the group annotation, and create an overlay with animations of the individual annotations yourself. Upon another touch, animate them back to the center, remove them and the overlay, and unhide the grouped annotation and re-enable the map.