XML : Google Map doesn't load in Fragment

I have a sliding tab fragment with two windows and the first one contains a google map view. The Fragments work fine and the Google fragment also gets shown, but the map doesn't load. Only a blank map with grid lines and a google logo gets shown. What is wrong with my code?

  public class CardFragment extends Fragment implements OnMapReadyCallback{    private static final String ARG_POSITION = "position";  private int position;    GoogleMap mMap;  Geocoder coder;    public static CardFragment newInstance(int position) {      CardFragment f = new CardFragment();      Bundle b = new Bundle();      b.putInt(ARG_POSITION, position);      f.setArguments(b);      return f;  }    public static MapsFragment newInstance(String s) {      Bundle args = new Bundle();      args.putString("value", s);      MapsFragment result = new MapsFragment();      result.setArguments(args);      return result;  }      @Override  public void onCreate(Bundle savedInstanceState) {      super.onCreate(savedInstanceState);      position = getArguments().getInt(ARG_POSITION);        }    @Override  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {  if(position == 0){          View rootView = inflater.inflate(R.layout.maps_frag,container,false);          ButterKnife.inject(this, rootView);          ViewCompat.setElevation(rootView, 50);            if(GooglePlayServicesUtil.isGooglePlayServicesAvailable(this.getContext()) == ConnectionResult.SUCCESS) {                MapView mapView = (MapView) rootView.findViewById(R.id.mymap);              mapView.onCreate(savedInstanceState);              mapView.getMapAsync(this);          }            return rootView;      } else {          View rootView = inflater.inflate(R.layout.list_frag,container,false);          ViewCompat.setElevation(rootView, 50);          return rootView;  }      @Override  public void onMapReady(final GoogleMap googleMap) {        mMap = googleMap;      coder = new Geocoder(this.getContext());      p1 = null;  }    

layout maps_frag

  <?xml version="1.0" encoding="utf-8"?>  <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:card_view="http://schemas.android.com/apk/res-auto"  xmlns:tools="http://schemas.android.com/tools"  android:layout_width="match_parent"  android:layout_height="match_parent">    <android.support.v7.widget.CardView  android:id="@+id/cardview"  android:layout_width="match_parent"  android:layout_height="match_parent"  card_view:cardBackgroundColor="@android:color/white">    <com.google.android.gms.maps.MapView     xmlns:android="http://schemas.android.com/apk/res/android"      xmlns:tools="http://schemas.android.com/tools"      android:id="@+id/swagishmap"      android:name="com.google.android.gms.maps.SupportMapFragment"      android:layout_width="match_parent"      android:layout_height="match_parent"      tools:context="com.locustapps.ingredientsapp.MapsActivity"/>    </android.support.v7.widget.CardView>    </FrameLayout>    

No comments:

Post a Comment