0

My project has navigation drawer with 5 fragments when instantiated the googleMap fragment for first time works fine ie shows googleMap with marker then when another fragment is selected from the navigation drawer and then try back to with googleMap fragment the Map doesn't load. why does this happen?

here's my code:

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();
    }
}

have tried this solution too <mapFragment.getMap() returns null>

What is the issue?

thanks,

1 Answer 1

0

getMap is deprecated, change to getMapAsync and tell if it helped.

1
  • edit question with changed code and post logcat output Mar 11, 2015 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.