ribl / FBAnnotationClusteringSwift

Swift translation of FB Annotation Clustering, which clusters pins on the map for iOS.
http://ribl.co/blog/2015/05/28/map-clustering-with-swift-how-we-implemented-it-into-the-ribl-ios-app/
MIT License
311 stars 109 forks source link

Dynamic annotation count #62

Closed mvorisis closed 7 years ago

mvorisis commented 7 years ago

Hi

My app every time the user scrolls the map gets lats,longs from my server and add new annotations to the map, so my question is can I use this library with dynamic annotations? I thought that I can somehow empty clusteringManager.

Thanks in advance.

antoinelamy commented 7 years ago

You can achieve that very easily by calling replace on clustering manager with your new annotations.

clusteringManager.replace(annotations: annotations)
mapView.showAnnotations(annotations, animated: false)
mvorisis commented 7 years ago

Thanks for answering me so quick, I have some questions though, Where should I use this command, and should I have to replace it with clusteringManager.addannotations?

antoinelamy commented 7 years ago

A replace is nothing more than a removeAll followed by a addannotations so you should replace it with addAnnotations if your new data set doesn't include old annotations that you want to keep on screen. You should call these methods when your network request completes.

mvorisis commented 7 years ago

Hi happy new year, to explain you how my app works i'll give you an example, my app launches and gets 3 annotations then every time I scroll it will get 3 more at a time (I have a function that checks if the annotation exists) so what do I have to add now in my code ?

mvorisis commented 7 years ago

Ok finally I found out what I was doing wrong.

I had a function to find out if the annotation I was going to add was existed. This is the for I was using : for existPin in annots as! Array<FBAnnotation> with this line I was taking cluster annotations too so I converted it to this: for existPin in array.

Every time I was inserting new annotations I used the line you told me clusteringManager.replace(annotations: annotations) but because I'm working on xcode 7 I used this line (the same but for swift 2) clusteringManager.setAnnotations(array).

Thank you for your time.

PS I didn't use mapView.showAnnotations(annotations, animated: false)