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
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);
}
});
}
});
}
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.