title: how do i solve integrating google map in fragment in android
body: <p>I have a problem integrating google map in fragment in android. I know how to do it in activity but fragment reference on this site are very old and not working in 2018. I don't have any error.below is fragment file. Any help will be highly appreciated. I have added API key and proper manifest file.</p>
  
  <pre><code>package com.example.narmail.truck30mint.Api.Fragments;
  
          import android.Manifest;
          import android.content.Context;
          import android.content.DialogInterface;
          import android.content.pm.PackageManager;
          import android.net.Uri;
          import android.os.Bundle;
          import android.support.annotation.NonNull;
          import android.support.v4.app.ActivityCompat;
          import android.support.v4.app.Fragment;
          import android.support.v4.content.ContextCompat;
          import android.support.v7.app.AlertDialog;
          import android.view.LayoutInflater;
          import android.view.View;
          import android.view.ViewGroup;
          import android.widget.TextView;
  
          import com.example.narmail.truck30mint.R;
          import com.google.android.gms.maps.CameraUpdateFactory;
          import com.google.android.gms.maps.GoogleMap;
          import com.google.android.gms.maps.MapView;
          import com.google.android.gms.maps.MapsInitializer;
          import com.google.android.gms.maps.OnMapReadyCallback;
          import com.google.android.gms.maps.model.CameraPosition;
          import com.google.android.gms.maps.model.LatLng;
          import com.google.android.gms.maps.model.MarkerOptions;
  
          import java.util.ArrayList;
  
          public class ViewTrucksFragment extends Fragment {
  
              TextView pageTitle;
              MapView mMapView;
              private GoogleMap googleMap;
  
              public ViewTrucksFragment() {
                  // Required empty public constructor
              }
  
              @Override
              public void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
              }
  
              @Override
              public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                       Bundle savedInstanceState) {
                  // Inflate the layout for this fragment
                  View rootView = inflater.inflate(R.layout.fragment_view_trucks, container, false);
                  pageTitle = rootView.findViewById(R.id.view_trucks_title);
                  String load_id =  getArguments().getString("load_id");
                  String load_from = getArguments().getString("load_from");
                  String load_to = getArguments().getString("load_to");
                  if (load_id != null &amp;&amp; load_from != null &amp;&amp; load_to != null) {
                      pageTitle.setText("Matching Trucks for "+load_from+" to "+load_to);
                  }
  
                  mMapView= rootView.findViewById(R.id.view_trucks_map);
                  mMapView.onCreate(savedInstanceState);
  
                  mMapView.onResume();
  
                  try {
                      MapsInitializer.initialize(getActivity().getApplicationContext());
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
  
                  mMapView.getMapAsync(new OnMapReadyCallback() {
                      @Override
                      public void onMapReady(GoogleMap mMap) {
                          googleMap = mMap;
                          googleMap.getUiSettings().setCompassEnabled(true);
                          googleMap.getUiSettings().setMyLocationButtonEnabled(true);
                          googleMap.getUiSettings().setRotateGesturesEnabled(true);
                          // For dropping a marker at a point on the Map
                          LatLng sydney = new LatLng(30.374219,76.782055);
                          googleMap.addMarker(new MarkerOptions().position(sydney).
                                  title("Title").snippet("TitleName"));
  
                          // For zooming automatically to the location of the marker
                          CameraPosition cameraPosition =                                                                           new CameraPosition.Builder().target(sydney).zoom(12).build();
                          googleMap.animateCamera(CameraUpdateFactory.newCameraPosition
                                  (cameraPosition ));
                      }
                  });
                  /*----------------*/
                  return rootView;
              }
          }
  </code></pre>
  
  <p>and below is my layout file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
          &lt;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"
              android:background="@color/colorWhite"
              tools:context=".Api.Fragments.ViewTrucksFragment"&gt;
  
             &lt;LinearLayout
                 android:orientation="vertical"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"&gt;
  
              &lt;TextView
                  android:id="@+id/view_trucks_title"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:textAlignment="center"
                  android:layout_marginRight="10dp"
                  android:layout_marginLeft="10dp"
                  android:padding="10dp"
                  android:textColor="@color/colorPrimary"
                  android:textSize="15sp"
                  android:text="@string/hello_blank_fragment" /&gt;
  
              &lt;com.google.android.gms.maps.MapView
                  android:id="@+id/view_trucks_map"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"&gt;
              &lt;/com.google.android.gms.maps.MapView&gt;
  
             &lt;/LinearLayout&gt;
  
          &lt;/FrameLayout&gt;
  </code></pre>