Multiple Annotations ( MKAnnotationView ) in the same location Coordinates

本秂侑毒 提交于 2019-12-06 01:05:12

问题


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.



来源:https://stackoverflow.com/questions/16381203/multiple-annotations-mkannotationview-in-the-same-location-coordinates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!