1
我可以建立谷歌地圖的實例,並查看地圖,但我不能的GetMap(),它總是空:谷歌地圖是空
mMapFragment = SupportMapFragment.newInstance();
FragmentTransaction fragmentTransaction = getSupportFragmentManager()
.beginTransaction();
fragmentTransaction.replace(R.id.container, mMapFragment);
fragmentTransaction.commit();
if (mMap == null) {
mMap = mMapFragment.getMap();
// always null, why?
if (mMap != null) {
mMap.getUiSettings().setMyLocationButtonEnabled(true);
}
}
後烏爾清單 – KOTIOS
更換片段是異步的,所以這個片段可能事件不會已經放在你的佈局,所以使的GetMap給你空。 您應該在此mapFragment事務結束後使用getMap方法替換/添加您的mapFragment和請求地圖 –
請參閱http://stackoverflow.com/a/14909970/1051804答案 –