首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >想要每10秒在谷歌地图上动画标记?

想要每10秒在谷歌地图上动画标记?
EN

Stack Overflow用户
提问于 2014-03-20 04:21:40
回答 1查看 1.7K关注 0票数 5

我已经在我的一个应用程序中实现了Google v2。现在,我想设置马克,连续动画每10秒的时间间隔,也可以看到信息窗口在任何时候。当用户点击它的时候,我已经激活了标记。但我要在每10秒自动动画标记。

代码下面的

代码语言:javascript
复制
    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;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-20 04:24:36

按照我的方式尝试:在您的CustomTimerTask中创建Activity

代码语言:javascript
复制
    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如下:

代码语言:javascript
复制
    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));

试试这个让我知道。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22523443

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档