I have a MKMapView that queries a server and displays an array of MKAnnotations when the center is changed but i’m experiencing the issue of duplicate MKAnnotations since I read them and add them.
I’m thinking on looking at each Annotation with a for and if it’s already there do nothing, but I think is not the best solution to solve this.
Any ideas?
Edit: I’m currently removing all of them and adding them again, which produces a flick for the user, thing i don’t want to happen
Basic Options
Depending on your situation, it might be easiest to simply remove all of the existing ones, and add all of your queried ones.
Are you having a particular problem where this isn’t working well for you?
More Advanced Option
Perhaps another, more interesting option, would be to split your map into grids the way Google does (zoom and grid x,y) The queries from the server should be specifically for a grid space, or a set of grid spaces – this way you’re not re-requesting duplicate information in the first place. It also would make it easier for you to determine what is and what isn’t already loaded. You could pre-request surrounding grid spaces in the background, and only load new grid spaces when the user scrolls out of the “already loaded” area.