【发布时间】:2015-03-10 22:07:16
【问题描述】:
我的项目有 导航抽屉,在第一次实例化 googleMap 片段时工作正常,即显示带有标记的 googleMap,然后从导航抽屉中选择另一个片段,然后尝试返回 googleMap地图不加载的片段。为什么会这样?
这是我的代码:
public class Contact_Us extends Fragment {
static final LatLng Annr = new LatLng(13.0846, 80.2179);
// static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
private static View mView;
SupportMapFragment mMapFragment = SupportMapFragment.newInstance();
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (mView != null) {
((ViewGroup) mView.getParent()).removeAllViews();
}
mView = inflater.inflate(R.layout.contact_us, null);
if (map == null) {
FragmentTransaction fragmentTransaction = getChildFragmentManager()
.beginTransaction();
fragmentTransaction.add(R.id.map, mMapFragment);
fragmentTransaction.commit();
}
return mView;
}
@Override
public void onStart() {
// TODO Auto-generated method stub
map = mMapFragment.getMap();
if (map != null) {
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);
Marker hamburg12 = map.addMarker(new MarkerOptions().position(
AnnaNagar).title("Reality Today"));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(Annr , 15));
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
super.onStart();
}
}
也尝试过这个解决方案mapFragment.getMap() returns null>
有什么问题?
谢谢,
【问题讨论】:
标签: android android-fragments google-maps-android-api-2