如何让谷歌使中心使用双击,捏来放大android的时候?双击、时候、中心、让谷歌使

2023-09-05 01:36:33 作者:哥,依旧颓废

我已经搜索谷歌地图中心,同时使用双击和捏放大变焦。我已经找到了Here,这仅适用于枪王变焦的解决方案。

I have search for google map center while zooming using double tap and pinch to zoom. I have found one solution for Here, This is only for double Tap to zoom solution.

TouchableWrapper

 public class TouchableWrapper extends FrameLayout {

    GestureDetectorCompat mGestureDetector;


    public TouchableWrapper(Context context) {
        super(context);
        mGestureDetector = new GestureDetectorCompat(context, mGestureListener);
    }


    private final GestureDetector.SimpleOnGestureListener mGestureListener
            = new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            Log.e("GestureDetector", "Executed");
            //Notify the event bus (I am using Otto eventbus of course) that you have just received a double-tap event on the map, inside the event bus event listener
            EventBus_Singleton.getInstance().post(new EventBus_Poster("double_tapped_map"));

            return true;
        }
    };

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        mGestureDetector.onTouchEvent(ev);
        return super.onInterceptTouchEvent(ev);
    }


}

我已经使用奥托的事件触发。

public class EventBus_Singleton {

    private static final Bus BUS = new Bus();

    public static Bus getInstance() {
        return BUS;
    }

    public EventBus_Singleton() {
    }

    public void post(String s) {
        BUS.post(s);
    }
}

EventBus_Poster

public class EventBus_Poster {
    public final String string;

    EventBus_Poster(String string) {
        this.string = string;
    }
}

在我的地图活动我都用事件的接收方法来放大地图上相同的位置。

In My Map Activity I have used event Receiving method to zoom map on same location.

 @Subscribe
    public void EventBus_singleton(EventBus_Poster event) {
        Log.e("EventBus_singleton", "Executed");
        if (event != null && event.string.equals("double_tapped_map")) {
            if (mapFragment != null) {
                mapFragment.getMap().getUiSettings().setZoomGesturesEnabled(false);
                mapFragment.getMap().getUiSettings().setRotateGesturesEnabled(false);

                mapFragment.getMap().setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
                    @Override
                    public void onCameraChange(CameraPosition cameraPosition) {
                        LatLng lng = cameraPosition.target;
                        Log.e("LatLng", "" + lng);
                    }
                });
                mapFragment.getMap().animateCamera(CameraUpdateFactory.zoomIn(), 400, null);
            }

        }
    }

我曾尝试使用 ScaleGestureDetector.SimpleOnScaleGestureListener 来使双指缩放,但它没有工作,也有时是滞后的。谁能帮我做双指缩放在谷歌地图?

I have tried to use ScaleGestureDetector.SimpleOnScaleGestureListener to make pinch zoom but it didnt work and also sometime it is lagging. Can anyone help me to make pinch zoom in google map?

推荐答案

嗯,我发现,试图做到这一点的时候,一个成功的双指缩放同时涉及速度和比例的条件。速度测量,以确定你是否真的要取决于你移动两个手指远离或更接近对方如何快速放大,你可以在里面谷歌地图和内部尤伯杯的应用程序试试这个,你实际上可以保持移动手指离开或接近对方,但由于速度太慢,你会的不可以触发放大地图/出大事!

Well, I've found that when trying to do this, a successful pinch-to-zoom involves both velocity and scale condition. Velocity is measured to determine whether you really want to zoom depending on how fast you moved the two fingers away from or closer to each other, you can try this inside Google Maps and inside Uber's app, you can actually keep moving the fingers away from or closer to each other but so slowly that you will not trigger a zoom in/out event on the map!

所以肯定涉及到的速度试图确定一个完整的缩放手势时。其次当然你也需要扩展,我已经打印出来的比例值,这是总是不是正好小的 1.0 当你开始捏缩小并始终大于1.0当你开始捏以放大。

So definitely involves velocity when trying to determine a full pinch gesture. Second of course you need scale also, and I've printed out the scale value and it is always smaller than exactly 1.0 when you start pinching to zoom out and always larger than 1.0 when you start pinching to zoom in.

这二者的结合无疑将让你更好的成绩,看速度首先我想说

Combination of these two will definitely get you better results, see velocity first I'd say

private final ScaleGestureDetector.OnScaleGestureListener mScaleGestureListener
        = new ScaleGestureDetector.SimpleOnScaleGestureListener() {
    /**
     * This is the active focal point in terms of the viewport. Could be a local
     * variable but kept here to minimize per-frame allocations.
     */

    float startingSpan;
    float startFocusX;
    float startFocusY;

    @Override
    public boolean onScaleBegin(ScaleGestureDetector scaleGestureDetector) {
        startingSpan = scaleGestureDetector.getCurrentSpan();
        startFocusX = scaleGestureDetector.getFocusX();
        startFocusY = scaleGestureDetector.getFocusY();

        return true;
    }

    @Override
    public boolean onScale(ScaleGestureDetector scaleGestureDetector) {
        float scale = scaleGestureDetector.getCurrentSpan() / startingSpan;

        mVelocityTracker.computeCurrentVelocity(1000);

        Log.d("VELOCITY", "X vel : " + mVelocityTracker.getXVelocity());
        Log.d("VELOCITY", "Y vel : " + mVelocityTracker.getYVelocity());

        if (scale <= 1.0) {
            EventBus_Singleton.getInstance().post(new EventBus_Poster("pinched_map", "out"));
        } else {
            EventBus_Singleton.getInstance().post(new EventBus_Poster("pinched_map", "in"));
        }

        return true;
    }
};
 
精彩推荐
图片推荐