如何处理使用谷歌地图Android版V2地图移动端? [英] How can I handle map move end using Google Maps for Android V2?

查看:110
本文介绍了如何处理使用谷歌地图Android版V2地图移动端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想尽快地图中心已经改变地理code类地址。

I want to geocode address as soon as map center has been changed.

如何处理映射moveend新的谷歌地图Android版V2? (我说的是这样,那么用户通过手指拖动地图)

How can I handle map moveend with new Google Maps for Android V2? (I'm talking about the case then user drags map by finger)

推荐答案

下面是一个可能的解决方法确定拖动开始和拖动结束事件:

Here is a possible workaround for determining drag start and drag end events:

您必须扩展SupportMapFragment或MapFragment。在onCreateView不得不将你的图形页面在自定义的FrameLayout(例如,在它下面是类TouchableWrapper),在其中截取的触摸事件,并确认地图是否被窃听或没有。如果你的onCameraChange被调用,只是检查是否在地图视图pressed与否(例如在下面,这是变量mMapIsTouched)。

You have to extend SupportMapFragment or MapFragment. In onCreateView you have to wrap your MapView in a customized FrameLayout (in example below it is the class "TouchableWrapper"), in which you intercepts touch events and recognizes whether the map is tapped or not. If your "onCameraChange" gets called, just check whether the map view is pressed or not (in example below this is the variable "mMapIsTouched").

例如code:

更新1:

  • 在getView回到原来创建的视图()
  • 而不是onInterceptTouchEvent使用dispatchTouchEvent()()

自定义的FrameLayout:

Customized FrameLayout:

private class TouchableWrapper extends FrameLayout {

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {

        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mMapIsTouched = true;
                break;
            case MotionEvent.ACTION_UP:
                mMapIsTouched = false;
                break;
        }

        return super.dispatchTouchEvent(ev);

    }

}

在自定义MapFragment:

In your customized MapFragment:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, 
        Bundle savedInstanceState) {
    mOriginalContentView = super.onCreateView(inflater, parent, 
            savedInstanceState);

    mTouchView = new TouchableWrapper(getActivity());
    mTouchView.addView(mOriginalContentView);

    return mTouchView;
}

@Override
public View getView() {
    return mOriginalContentView;
}

在你的相机变的回调方法:

In your camera change callback method:

private final OnCameraChangeListener mOnCameraChangeListener = 
        new OnCameraChangeListener() {

    @Override
    public void onCameraChange(CameraPosition cameraPosition) {
        if (!mMapIsTouched) {
            refreshClustering(false);
        }
    }
};

这篇关于如何处理使用谷歌地图Android版V2地图移动端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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