【发布时间】:2013-10-13 16:43:28
【问题描述】:
我正在尝试在片段中动态加载 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。
关于如何动态创建地图片段有什么建议吗?
【问题讨论】:
-
查看日志,很可能你没有在 play services 控制台中启用 google maps API。
-
no.. 当我们将 frgment 直接添加到 xml 文件时它会加载...但是....问题是... frgment.getmap() 返回 null.. 所以我不能向地图添加标记
标签: android google-maps-android-api-2 supportmapfragment