Locking on the map OnResume (); [closed]

1

I have the following code locking on the map in OnResume ();

Could anyone help me?

public class fragRegion extends MyFragment {

    private MapView mapRegio = null;
    private AlertDialog alertD = null;
    MyFragActivity myAct = null;
    private modHospital[] hospitals = null;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_region, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        alertD = new AlertDialog.Builder(getContext()).create();
        myAct = (MyFragActivity) getActivity();
        mapRegio = (MapView) getActivity().findViewById(R.id.mapRegio);
        myAct.setLoading(true);

        if (loadHosps()) {

            mapRegio.onCreate(savedInstanceState);
            mapRegio.getMapAsync(new OnMapReadyCallback() {
                @Override
                public void onMapReady(GoogleMap googleMap) {
                    LatLng userPosition = new LatLng(myAct.last_lat, myAct.last_lon);
                    for (modHospital h : hospitals) {
                        if (h.latitude != null && h.latitude.trim().length() > 0 && h.longitude != null && h.longitude.trim().length() > 0) {
                            LatLng hpos = new LatLng(Double.valueOf(h.latitude.replace(",",".")), Double.valueOf(h.longitude.replace(",",".")));
                            googleMap.addMarker(new MarkerOptions().position(hpos).title(h.name));
                        }
                    }
                    googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userPosition, 12f));
                    myAct.setLoading(false);
                }
            });
        } else {
            myAct.setLoading(false);
            alertD.setTitle(getActivity().getResources().getText(R.string.alertdiag_error).toString());
            alertD.setMessage("Não encontramos hospitais próximos a esta região");
            alertD.show();
        }

    }



    @Override
    public void onResume() {
        super.onResume();
        mapRegio.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        mapRegio.onPause();
    }

    @Override
    public void onStop() {
        super.onStop();
        mapRegio.onStop();
    }

    private boolean loadHosps() {
        dbHospitals dbH = new dbHospitals(getActivity());

        if (myAct.last_lat != null && myAct.last_lon != null) {
            hospitals = dbH.getNearHospitals(null, String.valueOf(myAct.last_lat), String.valueOf(myAct.last_lon), 10, 0);
            if(hospitals != null && hospitals.length > 0)
                return true;
        }
        return false;
    }

}
    
asked by anonymous 04.10.2016 / 16:38

0 answers