我在我的片段中顯示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,但我不想禁止改變方向。