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);
return view;
}
private void initializemap() {
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();
}
public void onDestroyView() {
super.onDestroyView();
SupportMapFragment f = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.mapView);
if (f != null){
getFragmentManager().beginTransaction().remove(f).commitAllowingStateLoss();
}
}
}
source
share