Java 在缩放android时禁用地图视图滚动

Java 在缩放android时禁用地图视图滚动,java,android,ios,google-maps,Java,Android,Ios,Google Maps,Google Map android是否有类似iOS Google Map.settings.allowScrollGesturesDuringRotateOrZoom的选项 基本上,我想要实现的是将标记的相对布局保持在地图的中心。您可以参考这一点。尽管由于scalegestruedetectorbug,它只能在API>16时工作。在API 16上启用缩放手势的情况下,使用常规的Mapview 公共类CustomEventMapView扩展了MapView{ 私人int手指=0; 私人谷歌地图谷

Google Map android是否有类似iOS Google Map.settings.allowScrollGesturesDuringRotateOrZoom的选项

基本上,我想要实现的是将标记的相对布局保持在地图的中心。

您可以参考这一点。尽管由于
scalegestruedetector
bug,它只能在API>16时工作。在API 16上启用缩放手势的情况下,使用常规的
Mapview

公共类CustomEventMapView扩展了MapView{
私人int手指=0;
私人谷歌地图谷歌地图;
私有长lastZoomTime=0;
私有浮动lastSpan=-1;
私有处理程序=新处理程序();
专用刻度尺测试器手势检测器;
公共CustomEventMapView(上下文上下文、GoogleMapOptions选项){
超级(上下文、选项);
}
公共CustomEventMapView(上下文){
超级(上下文);
}
@凌驾
public void getmapsync(最终OnMapReadyCallback回调){
super.getmapsync(新的OnMapReadyCallback(){
@凌驾
4月1日公开作废(最终谷歌地图谷歌地图){
gestureDetector=new-ScaleGestureDetector(getContext(),new-ScaleGestureDetector.OnScaleGestureListener()){
@凌驾
公共布尔标度(scalegestruedetector检测器){
if(lastSpan==-1){
lastSpan=检测器。getCurrentSpan();
}else if(detector.getEventTime()-lastZoomTime>=50){
lastZoomTime=detector.getEventTime();
animateCamera(CameraUpdateFactory.zoomBy(getZoomValue(detector.getCurrentSpan(),lastSpan)),50,null);
lastSpan=检测器。getCurrentSpan();
}
返回false;
}
@凌驾
公共布尔onScaleBegin(ScaleGetStereDetector检测器){
lastSpan=-1;
返回true;
}
@凌驾
标度仪上的公共空隙(标度仪检测器){
lastSpan=-1;
}
});
CustomEventMapView.this.googleMap=googleMap;
onMapReady(谷歌地图);
}
});
}
私有浮点getZoomValue(浮点currentSpan、浮点lastSpan){
double value=(Math.log(currentSpan/lastSpan)/Math.log(1.55d));
返回(浮动)值;
}
@凌驾
公共布尔dispatchTouchEvent(MotionEvent ev){
开关(ev.getAction()&MotionEvent.ACTION\u掩码){
case MotionEvent.ACTION\u指针\u向下:
手指=手指+1;
打破
case MotionEvent.ACTION\u指针\u向上:
手指=手指-1;
打破
case MotionEvent.ACTION\u UP:
手指=0;
打破
case MotionEvent.ACTION\u DOWN:
手指=1;
打破
}
如果(手指>1){
禁用滚动();
}否则如果(手指<1){
启用滚动();
}
如果(手指>1){
返回手势检测器。开触点(ev);
}否则{
返回超级dispatchTouchEvent(ev);
}
}
私有void启用滚动(){
if(googleMap!=null&&!googleMap.getUiSettings().isScrollGesturesEnabled()){
handler.postDelayed(新的Runnable(){
@凌驾
公开募捐{
googleMap.getUiSettings().setAllGesturesEnabled(true);
}
}, 50);
}
}
私有void disableScrolling(){
handler.removeCallbacksAndMessages(null);
if(googleMap!=null&&googleMap.getUiSettings().isScrollGesturesEnabled()){
googleMap.getUiSettings().setAllGesturesEnabled(false);
}
}
}
另外,这里有一个相关的线程可能会有所帮助:

您可以参考这个。尽管由于
scalegestruedetector
bug,它只能在API>16时工作。在API 16上启用缩放手势的情况下,使用常规的
Mapview

公共类CustomEventMapView扩展了MapView{
私人int手指=0;
私人谷歌地图谷歌地图;
私有长lastZoomTime=0;
私有浮动lastSpan=-1;
私有处理程序=新处理程序();
专用刻度尺测试器手势检测器;
公共CustomEventMapView(上下文上下文、GoogleMapOptions选项){
超级(上下文、选项);
}
公共CustomEventMapView(上下文){
超级(上下文);
}
@凌驾
public void getmapsync(最终OnMapReadyCallback回调){
super.getmapsync(新的OnMapReadyCallback(){
@凌驾
4月1日公开作废(最终谷歌地图谷歌地图){
gestureDetector=new-ScaleGestureDetector(getContext(),new-ScaleGestureDetector.OnScaleGestureListener()){
@凌驾
公共布尔标度(scalegestruedetector检测器){
if(lastSpan==-1){
lastSpan=检测器。getCurrentSpan();
}else if(detector.getEventTime()-lastZoomTime>=50){
lastZoomTime=detector.getEventTime();
animateCamera(CameraUpdateFactory.zoomBy(getZoomValue(detector.getCurrentSpan(),lastSpan)),50,null);
lastSpan=检测器。getCurrentSpan();
}
返回false;
}
@凌驾
公共布尔onScaleBegin(ScaleGetStereDetector检测器){
    public class CustomEventMapView extends MapView {

    private int fingers = 0;
    private GoogleMap googleMap;
    private long lastZoomTime = 0;
    private float lastSpan = -1;
    private Handler handler = new Handler();

    private ScaleGestureDetector gestureDetector;

    public CustomEventMapView(Context context, GoogleMapOptions options) {
        super(context, options);
    }

    public CustomEventMapView(Context context) {
        super(context);
    }

    @Override
    public void getMapAsync(final OnMapReadyCallback callback) {
        super.getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(final GoogleMap googleMap) {
                gestureDetector = new ScaleGestureDetector(getContext(), new ScaleGestureDetector.OnScaleGestureListener() {
                    @Override
                    public boolean onScale(ScaleGestureDetector detector) {
                        if (lastSpan == -1) {
                            lastSpan = detector.getCurrentSpan();
                        } else if (detector.getEventTime() - lastZoomTime >= 50) {
                            lastZoomTime = detector.getEventTime();
                            googleMap.animateCamera(CameraUpdateFactory.zoomBy(getZoomValue(detector.getCurrentSpan(), lastSpan)), 50, null);
                            lastSpan = detector.getCurrentSpan();
                        }
                        return false;
                    }

                    @Override
                    public boolean onScaleBegin(ScaleGestureDetector detector) {
                        lastSpan = -1;
                        return true;
                    }

                    @Override
                    public void onScaleEnd(ScaleGestureDetector detector) {
                        lastSpan = -1;

                    }
                });
                CustomEventMapView.this.googleMap = googleMap;
                callback.onMapReady(googleMap);
            }
        });
    }

    private float getZoomValue(float currentSpan, float lastSpan) {
        double value = (Math.log(currentSpan / lastSpan) / Math.log(1.55d));
        return (float) value;
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {

        switch (ev.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_POINTER_DOWN:
                fingers = fingers + 1;
                break;
            case MotionEvent.ACTION_POINTER_UP:
                fingers = fingers - 1;
                break;
            case MotionEvent.ACTION_UP:
                fingers = 0;
                break;
            case MotionEvent.ACTION_DOWN:
                fingers = 1;
                break;
        }
        if (fingers > 1) {
            disableScrolling();
        } else if (fingers < 1) {
            enableScrolling();
        }
        if (fingers > 1) {
            return gestureDetector.onTouchEvent(ev);
        } else {
            return super.dispatchTouchEvent(ev);
        }
    }

    private void enableScrolling() {
        if (googleMap != null && !googleMap.getUiSettings().isScrollGesturesEnabled()) {
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    googleMap.getUiSettings().setAllGesturesEnabled(true);
                }
            }, 50);
        }
    }

    private void disableScrolling() {
        handler.removeCallbacksAndMessages(null);
        if (googleMap != null && googleMap.getUiSettings().isScrollGesturesEnabled()) {
            googleMap.getUiSettings().setAllGesturesEnabled(false);
        }
    }
}