Map takes too long to initialize

Question

I've succeeded to display a map on fragment but it takes a lot of time, more than 4 seconds, until you see the map, this time seeing a black screen.

why is it happening? What is wrong in my code?

thanks!

<com.google.android.gms.maps.MapView>
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:enabled="true"
    </com.google.android.gms.maps.MapView>
public class MapFragment extends MainBaseFragment {
    private View mRoot = null;
    private MapView mMapView;
    private GoogleMap mMap;
    private Bundle mSavedInstanceState;


    public GoogleMap getmMap() {
        return mMap;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRetainInstance(true);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
        MapsInitializer.initialize(getActivity().getApplicationContext());
        this.mSavedInstanceState = savedInstanceState;   
        mRoot = inflater.inflate(R.layout.fragment_map, null);   
        try {
            MapsInitializer.initialize(getActivity());
        } catch (Exception e) {
            Log.e("Shanti", "Could not initialize google play", e);
        }
        setUpMapIfNeeded();

        return mRoot;
    }


    private void setUpMapIfNeeded() {
        mMapView = null;
        mMapView = (MapView) mRoot.findViewById(R.id.map);
        mMapView.onCreate(mSavedInstanceState);
        mMapView.onResume();
        if (mMapView != null) {
            mMap = mMapView.getMap();
            mMap.getUiSettings().setMyLocationButtonEnabled(true);
        }
    }

Show source
| java   | android   | google-maps   2016-12-05 09:12 0 Answers

Answers to Map takes too long to initialize ( 0 )

Leave a reply to - Map takes too long to initialize

◀ Go back