我正在尝试在片段中动态加载 SupportMapFragment,这是我的 onCreateView() 方法:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View contentView = inflater.inflate(R.layout.frag_map_layout, null);
shopDtos=ShopListFragment.shopDtos;
fragment =SupportMapFragment.newInstance();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.map_content, fragment);
ft.commit();
map = fragment.getMap();
mapMarker = map.addMarker(new MarkerOptions().position(new LatLng(0, 0))
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.maps_pin)));
return contentView;
}
不幸的是,我得到的 GoogleMap 地图为null
. 关于如何动态创建地图片段的任何建议?