5

I want to make a view like Sample image

in which a want to show google maps inside a bottom sheet fragment.

What I've tried

I've tried to show maps inside a bottom sheet dialog fragment but the output isn't what I desire.

What I require is a fixed size view which should be able to display maps. Currently my view is also responding to user gestures to change bottom sheet state but I require gestures to work on map only (e.g for map panning).

Hamza Ahmed Khan
  • 476
  • 5
  • 19
  • on a past project I created something similar using MapBox and bottom sheet. I found this guide to helpful: https://medium.com/@emrullahluleci/android-bottom-sheet-30284293f066 In your case you'd want the `bottom_sheet_content` to be your google map – Trevor Halvorson May 04 '17 at 18:41
  • Is there an other way you can suggest instead of bottom sheet? – Hamza Ahmed Khan May 04 '17 at 19:06
  • @HamzaAhmedKhan Did you find the solution? Actually, I have also similar kind of functionality. If you have found a solution, please share. Thanks in advance. – Harsh Patel Oct 31 '17 at 11:24

2 Answers2

11

When we use the map on BottomSheet, it conflicts touch events. So, need to disallow touch of BottomSheet.

Please find a below custom class which allows the map to move.

public class BottomSheetMapView extends MapView {

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

public BottomSheetMapView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public BottomSheetMapView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

public BottomSheetMapView(Context context, MapboxMapOptions options) {
    super(context, options);
}
@Override
public boolean onInterceptTouchEvent(final MotionEvent event) {
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            getParent().requestDisallowInterceptTouchEvent(true);
            break;
        case MotionEvent.ACTION_UP:
            getParent().requestDisallowInterceptTouchEvent(false);
            break;
        default:
            break;
    }

    return super.onInterceptTouchEvent(event);
}

}

I am using Mapbox. So, I use com.example.BottomSheetMapView instead of com.mapbox.mapboxsdk.maps.MapView in xml. Similarly, you can use Google map.

This satisfies your requirement.

Harsh Patel
  • 657
  • 11
  • 26
  • 1
    My friend, what you posted here is magical! Don't forget that you help a lot of devs with this solution. Thank you so much! I've been on an issue regarding this subject since 1 week. – sunlover3 Mar 20 '20 at 17:39
0

I need to implement the same feature. In my case, I used a BottomSheetDialogFragment that contains SupportMapFragment. The problem was, I could only make horizontal gestures on the map like panning it, but not vertical gestures. What needs to be done is to disable the BottomSheet's touch listener while the user is doing some gestures on the map. You can refer to my similar post here to see how it should be done https://stackoverflow.com/a/53740355/1767167

zeenosaur
  • 888
  • 11
  • 16