I would update your annotation layer directly as opposed to constantly replacing your annotation and thus its layer. You can do this by obtaining annotation.layer
, casting it to RMShape
, and then using methods like -addLineToCoordinate:
to update it.
Dynamically draw RMShape according to user location
Pregunta
I'm creating an array representing a path made by the user by adding the user's current location to an array. Each time a new point is being added, I remove the previous annotation, and add a new one. then the new path is being drawn on a mapView with RMShape
and layerForAnnotation
. The problem is that every time the RMSape
layer is being drawn, it has like a slide transition.
I have 2 questions:
- How do I fix this "slide" effect, and draw a continuous line representing the user's path smoothly?
- Is there a better way for tracing user's path?
.
-(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;
}
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow