我通过将用户的当前位置添加到数组来创建一个数组,该数组表示用户创建的路径。每次添加新点时,我都会删除以前的注释,然后添加一个新的。然后使用 RMShape
和 layerForAnnotation
在 mapView 上绘制新路径。问题是每次绘制 RMSape
层时,它都会像幻灯片一样过渡。
我有两个问题:
- 如何修复这种“滑动”效果,并平滑地绘制代表用户路径的连续线?
- 是否有更好的方法来追踪用户的路径?
.
-(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;
}
最佳答案
我会直接更新您的注释层,而不是不断替换您的注释及其层。为此,您可以获取 annotation.layer
,将其转换为 RMShape
,然后使用 -addLineToCoordinate:
等方法对其进行更新。
关于ios - 根据用户位置动态绘制RMShape,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23548551/