Ios 显示用户';地图上的位置

Ios 显示用户';地图上的位置,ios,iphone,uiviewcontroller,mapkit,Ios,Iphone,Uiviewcontroller,Mapkit,我正在创建一个带有地图和用户的应用程序。我从web服务器接收用户的位置。每5秒钟,我会通过新用户获得新的web数据,我会将用户添加到地图中: // after parsing web response I call [self.delegate addUserOnMap:user]; // and add users to the map MKPointAnnotation *point = [[MKPointAnnotation alloc] init]; CLLocationCoordin

我正在创建一个带有地图和用户的应用程序。我从web服务器接收用户的位置。每5秒钟,我会通过新用户获得新的web数据,我会将用户添加到地图中:

// 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];
但在地图上添加所有新用户之前,我会删除所有当前用户:

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;

所以,在做了这些之后,我的别针在闪烁,我不喜欢这样。如何修复它?

您必须停止删除所有注释以避免此问题。这将导致注释的视图从视图层次中删除,然后重新创建

更好的方法是在您自己的类中实现
MKAnnotation
,而不是使用
MKPointAnnotation
,并添加用于存储“touch”时间戳的属性。然后,在进行传递时,更新要保留的所有批注上的时间戳,然后执行移除传递以移除时间戳过期的所有批注