0

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

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

4

1 回答 1

0

保存状态的正常方法是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;
}
于 2016-12-07T12:40:04.780 回答