how to set google map fragment inside scroll view

后端 未结 8 892
北海茫月
北海茫月 2020-11-29 00:00

I want to set a Google map fragment inside vertical ScrollView, when I do the map does not zoom vertically, how can I override the touch event listener on

相关标签:
8条回答
  • 2020-11-29 00:22

    Update

    @Alok Nair's answer is very good however, the .getMap() method no longer works from android 9.2 onwards. Change the getMap method to .getMapAsync and add code in the onMapReady method

    Updated Solution, that works in Fragments

    if (gMap == null)
            {
              getChildFragmentManager().findFragmentById(R.id.map);
                SupportMapFragment mapFragment = (WorkaroundMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
                mapFragment.getMapAsync(new OnMapReadyCallback()
                {
                    @Override
                    public void onMapReady(GoogleMap googleMap)
                    {
                        gMap = googleMap;
                        gMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
                        gMap.getUiSettings().setZoomControlsEnabled(true);
    
                        mScrollView = mView.findViewById(R.id.advertScrollView); //parent scrollview in xml, give your scrollview id value
                        ((WorkaroundMapFragment) getChildFragmentManager().findFragmentById(R.id.map))
                                .setListener(new WorkaroundMapFragment.OnTouchListener()
                                {
                                    @Override
                                    public void onTouch()
                                    {
                                        mScrollView.requestDisallowInterceptTouchEvent(true);
                                    }
                                });
                    }
                });
            }
    
    0 讨论(0)
  • 2020-11-29 00:30

    I used the google maps listeners to resolve the scrolling issue of google map inside a scroll view.

        googleMap?.setOnCameraMoveStartedListener {
            mapView.parent.requestDisallowInterceptTouchEvent(true)
    
        }
    
        googleMap?.setOnCameraIdleListener {
            mapView.parent.requestDisallowInterceptTouchEvent(false)
    
        }
    

    By using this when you use start moving maps it disallows parent scrolling and when you stop moving maps then it allows scrolling.

    0 讨论(0)
提交回复
热议问题