I have a mapview that has a lot of annotations, most of them are very close to each other. What I want to do is similar to the Photo app on iOS where annotations are grouped when they are too close to each other and whenever you zoom out, they un grouped if they are too far apart.
I have seen this question already but the answer given isn't really what I was looking for.
I'm looking for either a library or a algorithm that I could implement myself.
Have a look here in order to see the full answer. It contains both implementations for MapKit and Google Maps. The code is inspired by WWDC 2011 video and works very well in my app.
I post the code for MapKit here anyway but there are a few useful remarks in my other answer.
One of Apple's WWDC 2011 session videos shows how to do exactly this. Go to https://developer.apple.com/videos/wwdc/2011/ (must be registered developer) and scroll to the video titled "Visualizing Information Geographically with MapKit". The basic idea is to use an offscreen map view to hold all of your annotations, and copy them to the onscreen map view as needed, making sure that you're not trying to show too many at once. It even does the nifty animation with the annotations as you zoom.