Reputation: 69
I am creating an application with a map and users on it. I receive users' locations from my web server. Every 5 seconds I got new web data with new users, I add users to the map:
// after parsing web response I call
[self.delegate addUserOnMap:user];
// and add users to the map
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
CLLocationCoordinate2D location;
location.latitude = [user.uLat doubleValue];
location.longitude = [user.uLon doubleValue];
point.coordinate = location;
point.title = [NSString stringWithFormat:@"Id: %@", user.uId];
point.subtitle = [NSString stringWithFormat:@"Distance: %@", user.uDistance];
[self.mapView addAnnotation:point];
But before adding all new users on map, I delete all current users:
id userLocation = [self.mapView userLocation];
NSMutableArray *pins = [[NSMutableArray alloc] initWithArray:[self.mapView annotations]];
if (userLocation != nil)
{
[pins removeObject:userLocation]; // avoid removing user location off the map
}
[self.mapView removeAnnotations:pins];
pins = nil;
So, after do this all, my pins are blinking, I not like this. How can I fix it?
Upvotes: 1
Views: 97
Reputation: 5128
You're going to have to stop removing all annotations to avoid this. This causes the annotations' views to be removed from the view hierarchy, then recreated.
A better approach would be to implement MKAnnotation
in your own class instead of using MKPointAnnotation
and add a property in which to store a "touch" timestamp. Then, when making your pass, update the timestamp on all of the annotations that you want to keep, then do a remove pass to remove all annotations with an out of date timestamp.
Upvotes: 1