我已成功在片段上显示地图,但需要花费大量时间,超过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);
}
}