Let's take a picture first:
cluster.gif
Let’s talk about the principle of implementation. First of all, the positioning little blue dot is composed of two pictures, a white circular picture at the bottom and a blue circular picture on the upper layer, as long as the transparency of the blue picture is continuously changed Animation operations can achieve this effect.
Take a look at Gaode's API
class Animation
java.lang.Object
com.amap.api.maps.model.animation.Animation
Directly known subclasses:
[AlphaAnimation](http://a.amap.com/lbs/static/unzip/Android_Map_Doc/3D/com/amap/api/maps/model/animation/AlphaAnimation.html), [AnimationSet](http://a.amap.com/lbs/static/unzip/Android_Map_Doc/3D/com/amap/api/maps/model/animation/AnimationSet.html), [RotateAnimation](http://a.amap.com/lbs/static/unzip/Android_Map_Doc/3D/com/amap/api/maps/model/animation/RotateAnimation.html), [ScaleAnimation](http://a.amap.com/lbs/static/unzip/Android_Map_Doc/3D/com/amap/api/maps/model/animation/ScaleAnimation.html), [TranslateAnimation](http://a.amap.com/lbs/static/unzip/Android_Map_Doc/3D/com/amap/api/maps/model/animation/TranslateAnimation.html)
It can be seen that it is actually the same as android, but there is a pitfall that is setRepeatCount(); setRepeatMode(); these two methods are not available. . This is a bit embarrassing, so let's start over.
1. Realize the positioning blue dot custom icon
//If the marker is not newly created, create a new one, and when it is created, set the location directly
if (mylocation == null) {
//Create a new marker object
MarkerOptions markerOptions1 = new MarkerOptions();
markerOptions1.icon(big); //设置底图图片
markerOptions1.position(new LatLng(location.getLatitude(), location.getLongitude())); //设置位置
bigPosition = aMap.addMarker(markerOptions1); //地图添加marker
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.icon(small);//设置上层图片
markerOptions.position(new LatLng(location.getLatitude(), location.getLongitude()));
mylocation = aMap.addMarker(markerOptions);
} else {
bigPosition.setPosition(new LatLng(location.getLatitude(), location.getLongitude()));
mylocation.setPosition(new LatLng(location.getLatitude(), location.getLongitude()));
}
2.设置动画
AlphaAnimation alpha = new AlphaAnimation(1, 0.2f);//新建透明度动画
alpha.setDuration(1500);//设置动画持续时间
mylocation.setAnimation(alpha);//图片设置动画
mylocation.startAnimation();//开始动画
mylocation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart() {
}
@Override
public void onAnimationEnd() {
AlphaAnimation alpha = new AlphaAnimation (0.2f, 1);
alpha.setDuration(1500);
mylocation.setAnimation (alpha);
mylocation.startAnimation ();
}
});
The effect of a breathing light is now achieved.
3. To achieve a continuous breathing light effect
Timer timer = new Timer ();
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
Mind();
}
};
timer.schedule(timerTask, 0, 3000);
In fact, it is just to play this animation repeatedly with a timer. At this point, the breathing light effect is realized.