Document Maps SDK for Android Guides Markers and Overlays Marker Animation

Marker Animation

Overview

The Smooth Marker Movement feature enables a marker to move smoothly along a predefined path based on a set of key points and a specified duration.

Use cases: This feature is ideal for visualizing vehicle trajectories, user movement paths, and other location-based animations.

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

Example:

Implementing Smooth Marker Movement

Related Interfaces

- Set the list of latitude/longitude coordinates for smooth movement: public void setPoints(List points)

- Set the total duration for smooth movement: public void setTotalDuration(int duration)

Set the icon for the moving marker: public void setDescriptor(BitmapDescriptor descriptor)

- Start smooth movement:  public void startSmoothMove()

- Stop smooth movement: public void stopMove()

Code Sample

 

// Get the list of track coordinates
List<LatLng> points = readLatLngs();
LatLngBounds bounds = new LatLngBounds(points.get(0), points.get(points.size() - 2));
mAMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50));

SmoothMoveMarker smoothMarker = new SmoothMoveMarker(mAMap);
// Set the icon for the moving marker
smoothMarker.setDescriptor(BitmapDescriptorFactory.fromResource(R.drawable.icon_car));

LatLng drivePoint = points.get(0);
Pair<Integer, LatLng> pair = SpatialRelationUtil.calShortestDistancePoint(points, drivePoint);
points.set(pair.first, drivePoint);
List<LatLng> subList = points.subList(pair.first, points.size());

// Set the list of track coordinates for smooth movement
smoothMarker.setPoints(subList);
// Set the total duration for smooth movement (in seconds)
smoothMarker.setTotalDuration(40);
// Start smooth movement
smoothMarker.startSmoothMove();