android的百度地圖開發(二) 定位

來源:互聯網
上載者:User

標籤:開啟   ring   0ms   tor   ntop   roi   等於   extend   imu   

參考: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
 @Override    public void onReceiveLocation(BDLocation location) {        MyLocationData locData = new MyLocationData.Builder()                .accuracy(location.getRadius())                // 此處設定開發人員擷取到的方向資訊,順時針0-360                .direction(100).latitude(location.getLatitude())                .longitude(location.getLongitude()).build();        // 設定定位元據        mBaiduMap.setMyLocationData(locData);        if (isFirstLoc) {            LatLng ll = new LatLng(location.getLatitude(), location.getLongitude());            MapStatusUpdate update = MapStatusUpdateFactory.newLatLngZoom(ll, 16);//設定地圖中心及縮放層級            mBaiduMap.animateMapStatus(update);            isFirstLoc = false;            Toast.makeText(getApplicationContext(), location.getAddrStr(), Toast.LENGTH_SHORT).show();        }    }
  •  

第四步,開始定位和關閉定位

mLocationClient.start(); //開啟定位
  • 1
mLocationClient.stop(); //關閉定位
 

android的百度地圖開發(二) 定位

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.