Map does not show location button after first start fragment

I have a map fragment with a name TestMap. When it is loaded first time, it shows the current location and the location of the button from the method setMyLocationButtonEnabled(true). When it loads after the first time, when it does not display the current position and location .......... Any idea why?

TestMap ...

 package com.example.map;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

public class TestMap extends Fragment{
    public  GoogleMap gmap;
    View view;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){

        view = inflater.inflate(R.layout.findmap, container, false);
        initializemap();
        gmap.setMyLocationEnabled(true);
        // gmap.getUiSettings().setMyLocationButtonEnabled(true);

        return view;
    }

    private void initializemap() {
        // TODO Auto-generated method stub
        if(gmap == null){
            gmap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.mapView))
                    .getMap();
        }
        if (gmap == null) {
            Toast.makeText(getActivity(),
                    "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                    .show();
        }   
    }

    public void onResume(){
        super.onResume();
        // initializemap();
    }

    public void onDestroyView() {
        super.onDestroyView();
        SupportMapFragment f = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.mapView);
        if (f != null){ 
            getFragmentManager().beginTransaction().remove(f).commitAllowingStateLoss();
        } 
    } 

}
+3
source share
1 answer

setMyLocationButtonEnabled() defaults to true.

     // Show current location    
        gmap.setMyLocationEnabled(true);
     //  Location button
     //comment this line gmap.getUiSettings().setMyLocationButtonEnabled(true);
0
source

All Articles