我在我的片段中显示GoogleMap。当我旋转屏幕时,地图会重新加载。在谷歌地图应用程序映射没有得到重新加载(地图消失,灰色的屏幕再次出现)谷歌地图V2防止地图重新加载旋转
我的代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_map, container,
false);
mMapView = (MapView) v.findViewById(R.id.map);
mMapView.onCreate(savedInstanceState);
mMapView.onResume();
if(savedInstanceState == null){
try {
MapsInitializer.initialize(getActivity().getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
}
if(googleMap == null){
googleMap = mMapView.getMap();
//map settings
googleMap.setMyLocationEnabled(true);
googleMap.setIndoorEnabled(false);
googleMap.setTrafficEnabled(false);
googleMap.getUiSettings().setTiltGesturesEnabled(false);
googleMap.getUiSettings().setMapToolbarEnabled(false);
}
if(savedInstanceState == null) {
Location myLocation = getMyLocation();
if (myLocation != null) {
double myLatitude = myLocation.getLatitude();
double myLongitude = myLocation.getLongitude();
CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(myLatitude, myLongitude)).zoom(12).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
}
return v;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mMapView.onSaveInstanceState(outState);
}
// and ofcouse onResume, OnPause, OnCreated and onLowMemory
我的相机现在的位置被保留,但地图是没有的。它重新加载,需要时间,看起来很丑。我怎样才能防止我的地图像谷歌地图应用程序重新加载?我看了一下this question,但我不想禁止改变方向。