我有以下代码:
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
ViewGroup view = (ViewGroup) inflater.inflate(R.layout.fragment_left, null);
// test
SupportMapFragment fragment = new SupportMapFragment();
FragmentManager fm = getActivity().getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.map, fragment).commit();
GoogleMap googleMap = fragment.getMap();
if(getCameraPosition() == null) { // first time in app
setCameraPosition(new CameraPosition(getYourLatLng(), 12, 0 ,0));
}
googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(getCameraPosition()));
googleMap.addMarker(new MarkerOptions()
.title("Your Position")
.snippet("This is where your smartphone is located.")
.position(getYourLatLng()));
return view;
}
这是我要在 xml 文件中替换的内容:
<FrameLayout
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
这是怎么回事?无论如何要更新ID?
新堆栈跟踪:
10-29 22:37:52.277: E/AndroidRuntime(16273): FATAL EXCEPTION: main
10-29 22:37:52.277: E/AndroidRuntime(16273): java.lang.NullPointerException: CameraUpdateFactory is not initialized
10-29 22:37:52.277: E/AndroidRuntime(16273): at com.google.android.gms.internal.s.b(Unknown Source)
10-29 22:37:52.277: E/AndroidRuntime(16273): at com.google.android.gms.maps.CameraUpdateFactory.aX(Unknown Source)