Skip to content Skip to sidebar Skip to footer

Googlemapview Is Not Loading Tiles

I have simple Fragment class, specialized for displaying Google Map: public class MapFragment extends Fragment implements Map, OnMapReadyCallback { private static final String

Solution 1:

You can make it work like this. This is having an additional benefit that the fragment can have other elements too displayed if needed.

publicclassDashBoardFragmentextendsFragment{
    private MapView mMapView;
    private GoogleMap mGoogleMap;
    @Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view= inflater.inflate(R.layout.fragment_dash_board, container, false);

        mMapView = (MapView) view.findViewById(R.id.map_dashBoard);
        mMapView.onCreate(savedInstanceState);
        mMapView.onResume();

        try {
            MapsInitializer.initialize(getActivity().getApplicationContext());
        } catch (Exception e) {
            e.printStackTrace();
        }
        mGoogleMap = mMapView.getMap();

    return view;
    }
}

xml for the fragment goes like this

<FrameLayoutxmlns: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"tools:context="com.screens.DashBoardFragment"><com.google.android.gms.maps.MapViewxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/map_dashBoard"android:layout_width="match_parent"android:layout_height="match_parent"
        /></FrameLayout>

Google play services should be available in device. You can check by using this.

publicstaticbooleanisGooglePlayServiceAvailable(Activity context){
        intstatus= GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
        if(status==ConnectionResult.SUCCESS){
            returntrue;
        }else{
            GooglePlayServicesUtil.getErrorDialog(status, context, 10).show();
            returnfalse;
        }
    }

And last but very much important , our map key should be present in Manifest

<meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="your google map key" />

Solution 2:

You have to call the 'getMapAsync()' function to display the map.In your onCreateView use getMapAsync() to set the callback on the fragment.

Here's a sample code for getMapAsync:

MapFragmentmapFragment= (MapFragment) getFragmentManager()
.findFragmentById(R.id.map); mapFragment.getMapAsync(this);

You may also try to read the Official Google Documentation for MapFragment: https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#getMapAsync(com.google.android.gms.maps.OnMapReadyCallback)

Post a Comment for "Googlemapview Is Not Loading Tiles"