我必须在我的一个应用程序中实现Google map v2。现在我想设置Marker,它可以连续动画每10秒钟的时间间隔以及可见的信息窗口。当用户点击它时,我已经为Marker设置了动画。但我想每10秒钟自动设置一个动画标记。
代码如下:
static final LatLng SECC = new LatLng(55.8607, -4.2871);
private Marker mPerth;
mPerth = mMap
.addMarker(new MarkerOptions()
.position(SECC)
.title("SECC")
.snippet(
"Exhibition Way, Glasgow, G3 8YW\nSports: Boxing, Gymnastics, Judo, Netball, Wrestling, Weightlifting"));
@Override
public boolean onMarkerClick(final Marker marker) {
if (marker.equals(mPerth)) {
// This causes the marker at Perth to bounce into position when it
// is clicked.
final Handler handler = new Handler();
final long start = SystemClock.uptimeMillis();
final long duration = 1500;
final Interpolator interpolator = new BounceInterpolator();
handler.post(new Runnable() {
@Override
public void run() {
long elapsed = SystemClock.uptimeMillis() - start;
float t = Math.max(
1 - interpolator.getInterpolation((float) elapsed
/ duration), 0);
mPerth.setAnchor(0.5f, 1.0f + 2 * t);
if (t > 0.0) {
// Post again 16ms later.
handler.postDelayed(this, 16);
}
}
});
} else if (marker.equals(mAdelaide)) {
// This causes the marker at Adelaide to change color.
marker.setIcon(BitmapDescriptorFactory.defaultMarker(new Random()
.nextFloat() * 360));
}
return false;
}
答案 0 :(得分:7)
按照我的方式尝试:在CustomTimerTask
Activity
课程
class CustomTimerTask extends TimerTask {
private Context context;
private Handler mHandler = new Handler();
// Write Custom Constructor to pass Context
public CustomTimerTask(Context con) {
this.context = con;
}
@Override
public void run() {
new Thread(new Runnable() {
@Override
public void run() {
mHandler.post(new Runnable() {
@Override
public void run() {
final Handler handler = new Handler();
final long start = SystemClock.uptimeMillis();
final long duration = 3000;
final Interpolator interpolator = new BounceInterpolator();
handler.post(new Runnable() {
@Override
public void run() {
long elapsed = SystemClock.uptimeMillis() - start;
float t = Math.max(
1 - interpolator.getInterpolation((float) elapsed
/ duration), 0);
mPerth.setAnchor(0.5f, 0.1f+1*t);
if (t > 0.0) {
// Post again 16ms later.
handler.postDelayed(this, 16);
}
}
});
}
});
}
}).start();
}
}
并设置您的Marker
,如:
mPerth = mMap
.addMarker(new MarkerOptions()
.position(SECC)
.title("SECC")
.snippet("Exhibition Way, Glasgow, G3 8YW\nSports: Boxing, Gymnastics, Judo, Netball, Wrestling, Weightlifting"));
Timer timer = new Timer();
TimerTask updateProfile = new CustomTimerTask(youractivity.this);
timer.scheduleAtFixedRate(updateProfile, 10,5000);
mPerth.showInfoWindow();
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(SECC, 18.0f));
试试这个,让我知道。