处理百度地图方向变化

Handle orientation changes in baidu maps

在百度地图中处理方向变化的正确方法是什么?

似乎没有getter或setter获取当前显示地图的中心和缩放级别或边界。

保存状态的正常方式是onSaveInstanceState(...)回调。我在这里写了这段代码:

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putParcelable("map", mapView.getMap().getMapStatus());
}

当你想恢复数据时试试这个例子(取自片段):

@Nullable
@Override
public synchronized View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.baido_map, container, false);
    mapView = (MapView) view.findViewById(R.id.baido_map);

    if(savedInstanceState != null) {
        mapView.getMap().setMapStatus(MapStatusUpdateFactory.newMapStatus(savedInstanceState.getParcelable("map")));
    }

    return view;
}