android的百度地图开发(二) 定位
生活随笔
收集整理的這篇文章主要介紹了
android的百度地图开发(二) 定位
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
參考:http://blog.csdn.net/mr_wzc/article/details/51590485
第一步,初始化LocationClient類
//獲取地圖控件引用mMapView = (MapView) findViewById(R.id.bmapView);mLocationClient = new LocationClient(getApplicationContext()); //聲明LocationClient類mLocationClient.registerLocationListener(this);//注冊監聽函數 initLocation(); // 開啟定位圖層 mBaiduMap = mMapView.getMap(); mBaiduMap.setMyLocationEnabled(true);//顯示定位層并且可以觸發定位,默認是flase mLocationClient.start();//開啟定位第二步,配置定位SDK參數?
private void initLocation() { LocationClientOption option = new LocationClientOption(); option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy );//可選,默認高精度,設置定位模式,高精度,低功耗,僅設備 option.setCoorType("bd09ll");//可選,默認gcj02,設置返回的定位結果坐標系 int span = 1000; option.setScanSpan(span);//可選,默認0,即僅定位一次,設置發起定位請求的間隔需要大于等于1000ms才是有效的 option.setIsNeedAddress(true);//可選,設置是否需要地址信息,默認不需要 option.setOpenGps(true);//可選,默認false,設置是否使用gps option.setLocationNotify(true);//可選,默認false,設置是否當gps有效時按照1S1次頻率輸出GPS結果 option.setIsNeedLocationDescribe(true);//可選,默認false,設置是否需要位置語義化結果,可以在BDLocation.getLocationDescribe里得到,結果類似于“在北京天安門附近” option.setIsNeedLocationPoiList(true);//可選,默認false,設置是否需要POI結果,可以在BDLocation.getPoiList里得到 option.setIgnoreKillProcess(false);//可選,默認true,定位SDK內部是一個SERVICE,并放到了獨立進程,設置是否在stop的時候殺死這個進程,默認不殺死 option.SetIgnoreCacheException(false);//可選,默認false,設置是否收集CRASH信息,默認收集 option.setEnableSimulateGps(false);//可選,默認false,設置是否需要過濾gps仿真結果,默認需要 mLocationClient.setLocOption(option); }
第三步,實現BDLocationListener接口,并實現未完成的方法
public class MainActivity extends Activity implements BDLocationListener {- 1
- ?
第四步,開始定位和關閉定位
mLocationClient.start(); //開啟定位- 1
轉載于:https://www.cnblogs.com/manmanlu/p/7761918.html
總結
以上是生活随笔為你收集整理的android的百度地图开发(二) 定位的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: .net core 一个避免跨站请求的中
- 下一篇: 11月深度学习班第5课图像物体检测:rc