Document Maps SDK for iOS Guides Markers and Overlays Marker Animation

Marker Animation

Overview

The animated annotation feature enables smooth point movement along a specified path based on key coordinates and time parameters. This is commonly used for visualizing vehicle trajectories, user movement paths, and other location tracking scenarios.

Version requirements: 3D Map SDK V4.5.0 or later.

Implement Animated Annotation Movement

Header Files

MAAnimatedAnnotation.h

MAAnnotationMoveAnimation.h

Interfaces

MAAnimatedAnnotation.h

The following code snippet is provided in Objective-C:

@interface MAAnimatedAnnotation : MAPointAnnotation<MAAnimatableAnnotation>

/**
 @brief Adds a movement animation. The first animation added uses the current coordinate as the starting point and moves along the specified coordinates array. Subsequent animations use the end point of the previous animation as the starting point. since 4.5.0
 @param coordinates Array of coordinates
 @param count Number of coordinates to pass
 @param duration Animation duration. 0 or negative values indicate no animation
 @param name Animation name. Pass nil if not specified
 @param completeCallback Callback when the animation completes. isFinished: whether the animation completed successfully
 */
- (void)addMoveAnimationWithKeyCoordinates:(CLLocationCoordinate2D *)coordinates
                                     count:(NSUInteger)count
                              withDuration:(CGFloat)duration
                                  withName:(NSString *)name
                          completeCallback:(void(^)(BOOL isFinished))completeCallback;

/**
 Retrieves all unfinished movement animations. Returns an array of MAAnnotationMoveAnimation objects. since 4.5.0
 */
- (NSArray<MAAnnotationMoveAnimation*> *)allMoveAnimations;

/**
 * Movement direction. since 4.5.0
 */
@property (nonatomic, assign) CLLocationDirection movingDirection;

@end

Steps

1. Add an Annotation to the Map

Add an annotation to the map. The annotation must inherit from MAAnimatedAnnotation, or implement the MAAnimatableAnnotation protocol and provide its own animation logic.

2. Add an Animation

Call the addMoveAnimationWithKeyCoordinates method on the annotation to add the animation.

[self.annotation addMoveAnimationWithKeyCoordinates:coords1 count:sizeof(coords1) / sizeof(coords1[0]) withDuration:5 withName:nil completeCallback:^(BOOL isFinished) {
    // Animation completion handling
}];

3. Cancel Unfinished Animations

To stop all ongoing animations, iterate through the animation array and cancel each one.

for (MAAnnotationMoveAnimation *animation in [self.annotation allMoveAnimations]) {
    [animation cancel];
}