我有一个名为
TestMap
的地图片段。当它首先加载时 时间,它从方法显示当前位置和位置按钮setMyLocationButtonEnabled(true)
。当它首先加载后 时间不显示当前位置和位置按钮......... 知道为什么吗?
... 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();
}
}
}
答案 0 :(得分:0)
setMyLocationButtonEnabled()
默认为true。
// Show current location
gmap.setMyLocationEnabled(true);
// Location button
//comment this line gmap.getUiSettings().setMyLocationButtonEnabled(true);