一个fragment中简单应用,就项目而言可能没有框架但是可以使用
public class app_safety_Fragment extends Fragment implements OnGetGeoCoderResultListener {
private static final String TAG="app_safety_Fragment";
private MapView mMapView=null;
private BaiduMap mBaiduMap;
// 定位相关
LocationClient mLocClient;
boolean isFirstLoc = true;// 是否首次定位
LocationClientOption option = null;
GeoCoder mSearch = null; // 搜索模块,也可去掉地图模块独立使用
private TextView textView_message;
private TextView textView_s;
public MyLocationListener myListener = new MyLocationListener();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//在使用百度地图SDK各组件之前初始化context信息,传入ApplicationContext
//注意该方法要再setContentView方法之前实现
SDKInitializer.initialize(getActivity().getApplicationContext());
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_app_safety, container, false);
mMapView =(MapView) view.findViewById(R.id.map_view);
textView_message = (TextView) view.findViewById(R.id.textView_message);
textView_s=(TextView)view.findViewById(R.id.textView_s);
mBaiduMap = mMapView.getMap();
// 初始化搜索模块,注册事件监听
mSearch = GeoCoder.newInstance();
mSearch.setOnGetGeoCodeResultListener(this);
// 开启定位图层
mBaiduMap.