映射需要很长时间才能初始化

时间:2016-12-05 08:55:21

标签: java android google-maps

我已成功在片段上显示地图,但需要花费大量时间,超过4秒,直到您看到地图,这次看到黑屏。

为什么会这样? 我的代码出了什么问题?

谢谢!

<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);
        }
    }

0 个答案:

没有答案