如何处理使用谷歌地图Android版V2地图移动端?地图、如何处理、Android

2023-09-13 02:34:00 作者:獨霸你的美

我想尽快地图中心已经改变地理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);
        }
    }
};