【问题标题】:Smooth Movement of annotation image on MapviewMapview上注释图像的平滑移动
【发布时间】:2012-03-29 22:15:00
【问题描述】:

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

更新当前的经度和纬度后,我正在使用以下代码刷新地图

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

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

【问题讨论】:

    标签: iphone ios4 mkmapview mkpinannotationview mkmapviewdelegate


    【解决方案1】:

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

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

    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 Docs 专门将 'setCoordinate' 方法称为应该用于支持拖动或频繁更新的方法。

    【讨论】:

    • 我知道问题在于在地图视图上删除和添加注释,但有没有其他方法可以做到这一点?您能详细告诉我该怎么做吗?
    • 嘿,感谢您的回复。但它不起作用。它仍然让我有跳跃的效果。
    • 很抱歉听到这个消息,希望我有更多的求助电话经验。干杯,祝你好运。
    【解决方案2】:

    您不得从地图中删除注释。而是更改 UIView beginAnimations-commitAnimations 块中的注释坐标;

    它看起来像这样:

    [UIView beginAnimations:@"yourAnimationName" context:nil];
    [UIView setAnimationDuration:1.0];
    [yourAnnotation setCoordinate:yourNewCoordinate];
    [UIView commitAnimations];
    

    它将平滑地移动注释。

    BR, 马辛·舒尔茨

    【讨论】:

      【解决方案3】:
      //SWIFT 3
      UIView.beginAnimations("yourname", context: nil)
      UIView.setAnimationDuration(1.0)
      yourpin.coordinate = MKCoordinateForMapPoint(mycoordinate)
      UIView.commitAnimations()
      

      【讨论】:

        猜你喜欢
        • 2015-01-22
        • 1970-01-01
        • 2018-09-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-10
        相关资源
        最近更新 更多