miibpa February 2016

CameraUpdate, SupportMapFragment inside ViewPager, not loading second time

I'm facing problems when placing SupportMapFragment inside a fragment that is part of a viewpager with 5 tabs, everything works correctly when viewpager loads the map for first time, but not showing anything whe comming back from another tab. I load the map as follows:

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    FragmentManager fm = getFragmentManager();
    mapFragment = (SupportMapFragment) fm.findFragmentById(R.id.map_estate);
    if (mapFragment == null) {
        mapFragment = SupportMapFragment.newInstance();
        fm.beginTransaction().replace(R.id.map_estate, mapFragment).commit();
    }
    mapFragment.getMapAsync(this);
}

and then use it like:

@Override
public void onMapReady(GoogleMap googleMap) {
    this.map = googleMap;
    this.map.setMyLocationEnabled(true);
    this.map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
    this.map.getUiSettings().setMyLocationButtonEnabled(false); 
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(center, 16);
    mapFragment.getMap().moveCamera(cameraUpdate);
}

Anyone facing same problem? Thanks in advance

Answers


miibpa February 2016

ReplacingFragmentManager fm = getFragmentManager(); for FragmentManager fm = getChildFragmentManager(); solved the problem.

Post Status

Asked in February 2016
Viewed 2,697 times
Voted 5
Answered 1 times

Search




Leave an answer