我正在尝试将 StreetViewPanorama 的当前位置保存在 StreetViewFragment 中,例如,如果用户最初处于 Portrait 状态并通过点击箭头更改 StreetViewPanorama 中的位置并探索该区域,然后切换到 Landscape 我想设置要恢复的最后一个位置,以便用户可以继续探索该区域。目前,当我尝试访问“streetViewPanorama.getLocation()”时,streetViewPanorama 为 Null,但这不是问题。我觉得我的救国方式不对,应该有更好的方式。所以我在征求你的建议,拜托!
这是我的 StreetViewFragment 的代码:
public class StreetViewFragment extends ViperFragment implements OnStreetViewPanoramaReadyCallback,
PropertyDetailsStreetView {
private static final String KEY_PROPERTY_ID = "property_id_street_view";
private static final String KEY_PROPERTY_LAT = "property_lat";
private static final String KEY_PROPERTY_LON = "property_lon";
private Bundle savedInstances;
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
streetViewPanoramaFragment = (StreetViewPanoramaFragment)
getActivity().getFragmentManager().findFragmentById(R.id.streetviewpanorama);
streetViewPanoramaFragment.getStreetViewPanoramaAsync(this);
savedInstances = savedInstanceState;
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putDouble(KEY_PROPERTY_LAT, streetViewPanorama.getLocation().position.latitude);
outState.putDouble(KEY_PROPERTY_LON, streetViewPanorama.getLocation().position.longitude);
super.onSaveInstanceState(outState);
}
@Override
public void onStreetViewPanoramaReady(StreetViewPanorama streetViewPanorama) {
this.streetViewPanorama = streetViewPanorama;
presenter.onStreetViewPanoramaReady(getArguments().getLong(KEY_PROPERTY_ID));
if (savedInstances != null) {
this.streetViewPanorama.setPosition(
new LatLng(savedInstances.getLong(KEY_PROPERTY_LAT),
savedInstances.getLong(KEY_PROPERTY_LON)));
}
}