Mapview上注释图像的平滑移动

Aks*_*her 8 iphone mkpinannotationview mkmapview ios4 mkmapviewdelegate

我已经为用户当前位置加载了自定义注释图像.我在后台每1秒后更新当前用户位置.

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[self performSelectorOnMainThread:@selector(tempupdate) withObject:nil waitUntilDone:NO];
[pool release];

-(void)tempupdate
{
    NSLog(@"callToLocationManager");
    mylocationManager = [[CLLocationManager alloc]init];
    NSLog(@"locationManagerM = %@",mylocationManager);
    mylocationManager.delegate = self;
    mylocationManager.desiredAccuracy = kCLLocationAccuracyBest;
    mylocationManager.distanceFilter = 500;
    [mylocationManager startUpdatingLocation];
}
Run Code Online (Sandbox Code Playgroud)

更新当前latutude和经度后,我使用以下代码刷新地图

MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.002;
span.longitudeDelta=0.002;
CLLocationCoordinate2D location;
location.latitude=[lat doubleValue];
location.longitude=[longt doubleValue];
region.span=span;
region.center=location;
addAnnotation=[[AddressAnnotation alloc]initWithCoordinate:location];
addAnnotation.mTitle=@"You are here";
[self.mapView removeAnnotations:self.mapView.annotations];
[self.mapView addAnnotation:addAnnotation];
[self.mapView setRegion:region animated:TRUE];
[self.mapView regionThatFits:region];
Run Code Online (Sandbox Code Playgroud)

但每次自定义注释图像在添加到地图之前闪烁.如何避免这种闪烁效应?

Mob*_*Vet 3

我还没有对此进行测试,但是根据对您的代码的快速浏览,我猜测问题在于您删除了注释,然后添加了新注释。

您是否尝试过仅编辑已附加注释的属性?

NSArray* curAnnotations = [mapView annotations];
AddressAnnotation* aa = [curAnnotations lastObject]; // I am assuming you only have 1 annotation
aa.mTitle = @"You are here"; // or don't do this if it never changes
[aa setCoordinate:location];
Run Code Online (Sandbox Code Playgroud)

注意: Apple 文档特别指出“setCooperative”方法应该用于支持拖动或频繁更新。