[英]Want to animate Marker in every 10 seconds in google map?
I have to implemented Google map v2 in my one application. 我必须在我的一个应用程序中实现Google map v2。 now i want to set up Marker that continuously animate every 10 seconds time interval and also visible info window at all time.
现在我想设置Marker,它可以连续动画每10秒钟的时间间隔以及可见的信息窗口。 i already animate Marker when user tap on it.
当用户点击它时,我已经为Marker设置了动画。 but i want animate Marker automatically at every 10 seconds.
但我想每10秒钟自动设置一个动画标记。
Below code: 代码如下:
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;
}
Try as per my way: create CustomTimerTask
class in your Activity
按照我的方式尝试:在
Activity
创建CustomTimerTask
类
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();
}
}
And setup your Marker
like: 并设置你的
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));
try this and let me know. 试试看,让我知道。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.