GoogleMap仅在替代尝试安卓时加载

时间:2015-03-09 10:27:48

标签: android android-fragments google-maps-android-api-2

我的项目有导航抽屉,5个片段在实例化时首次使用谷歌地图片段工作正常,然后用标记显示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 >

问题是什么?

感谢,

1 个答案:

答案 0 :(得分:0)

getMap已弃用,请更改为getMapAsync并告知是否有帮助。