Android地图:如何确定地图中心一拖完成后 [英] android maps: how to determine map center after a drag has been completed

查看:134
本文介绍了Android地图:如何确定地图中心一拖完成后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有通过Android的地图API,在那里我可以检测出地图中心平移后完成动画的方式?我想用这个信息来从服务器动态加载标记。 谢谢 BD

Is there a way through the android maps API, where I can detect the map center after pan animation has completed? I want to use this information to load markers from a server dynamically. Thanks BD

推荐答案

我也一直在寻找一个做了结尾拖解决方案,检测在地图移动结束后,正好在那一刻地图中心。我还没有找到它,所以我做了这个简单的实现细做的工作:

I also have been looking for a "did end drag" solution that detects the map center at the moment exactly after the map ended moving. I haven't found it, so I've made this simple implementation that did work fine:

private class MyMapView extends MapView {

    private GeoPoint lastMapCenter;
    private boolean isTouchEnded;
    private boolean isFirstComputeScroll;

    public MyMapView(Context context, String apiKey) {
        super(context, apiKey);
        this.lastMapCenter = new GeoPoint(0, 0);
        this.isTouchEnded = false;
        this.isFirstComputeScroll = true;
    }
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN)
            this.isTouchEnded = false;
        else if (event.getAction() == MotionEvent.ACTION_UP)
            this.isTouchEnded = true;
        else if (event.getAction() == MotionEvent.ACTION_MOVE)
            this.isFirstComputeScroll = true;
        return super.onTouchEvent(event);
    }
    @Override
    public void computeScroll() {
        super.computeScroll();
        if (this.isTouchEnded &&
            this.lastMapCenter.equals(this.getMapCenter()) &&
            this.isFirstComputeScroll) {
            // here you use this.getMapCenter() (e.g. call onEndDrag method)
            this.isFirstComputeScroll = false;
        }
        else
            this.lastMapCenter = this.getMapCenter();
    }
}

就这样,我希望它能帮助! O /

That's it, I hope it helps! o/

这篇关于Android地图:如何确定地图中心一拖完成后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆