根据用户位置动态绘制RMShape

时间:2014-05-08 17:23:08

标签: ios mapbox

我通过将用户的当前位置添加到数组来创建表示用户所做路径的数组。每次添加新点时,我都会删除以前的注释,然后添加一个新注释。然后使用RMShapelayerForAnnotation在mapView上绘制新路径。问题是,每次绘制RMSape图层时,它都像幻灯片过渡一样。

我有两个问题:

  1. 我如何解决这个问题" slide"效果,并画出一条代表用户路径的连续线?
  2. 有没有更好的方法来追踪用户的路径?
  3. -(void)mapView:(RMMapView *)mapView didUpdateUserLocation:(RMUserLocation *)userLocation
    {
    
            if (path) {
                [self.mapView removeAnnotation:path];
            }
    
            path = [[RMShapeAnnotation alloc] initWithMapView:mapView points:points];
    
            [mapView addAnnotation:path];
    
    }
    
    
    
    - (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation
    {
    
        if (annotation.isUserLocationAnnotation) {
            return nil;
        }
    
        if ([annotation isKindOfClass:[RMShapeAnnotation class]]) {
    
            for (int i = 0; i < points.count; i++) {
                CLLocation *location = points[i];
                [self.path addLineToCoordinate:location.coordinate];
    
             }
    
            return self.path;
    
        }
    
        return nil;
    }
    

1 个答案:

答案 0 :(得分:1)

我会直接更新您的注释图层,而不是不断更换注释,从而更换图层。您可以通过获取annotation.layer,将其投放到RMShape,然后使用-addLineToCoordinate:等方法对其进行更新来实现此目的。