In your xml layout you have to do this
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <com.google.android.gms.maps.MapView android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent"/> </FrameLayout>
inside your fragment implement this
private MapView mapView; private GoogleMap googleMap;
override onCreateView if onCreateView does not exist, as in the code below
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.your_layout, container, false); }
override onViewCreated () inside this onViewCreated () insert this
mapView = (MapView) view.findViewById(R.id.map); mapView.onCreate(savedInstanceState); mapView.onResume(); mapView.getMapAsync(this);
when you have already implemented OnMapReadyCallback in your snippet, add this code / like this
@Override public void onMapReady(GoogleMap map) { googleMap = map; }
hope this helps you.
Lester L.
source share