gpt4 book ai didi

iphone - Mapview 上注释图像的平滑移动

转载 作者:行者123 更新时间:2023-12-03 18:36:24 26 4
gpt4 key购买 nike

我已加载用户当前位置的自定义注释图像。我将在后台每 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];
}

更新当前纬度和经度后,我使用以下代码刷新 map

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];

但是每次自定义注释图像在添加到 map 之前都会闪烁。如何避免这种闪烁效果?

最佳答案

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

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

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];

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

关于iphone - Mapview 上注释图像的平滑移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9685273/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com