高德地圖-定位幫助類

高德地圖-定位幫助類

第一步:新建LocationClient實(shí)例

    //LocationClient實(shí)例
    private AMapLocationClient locationClient = null;

    /**
     * 新建LocationClient
     * @param context
     * @return
     */
    public LocationHelper newLocationClient(Context context){
        locationClient = new AMapLocationClient(context);
        return this;
    }

第二步:設(shè)置定位監(jiān)聽

   /**
     * 設(shè)置定位監(jiān)聽
     * @param listener
     * @return
     */
    public LocationHelper setLocationListener(AMapLocationListener listener){
        if (locationClient != null && listener != null) {
            locationClient.setLocationListener(listener);
        }
        return this;
    }

第三步:初始化定位選項(xiàng)

    /**
     * 初始化定位選項(xiàng)
     * @return
     */
    public LocationHelper initLocationClient(){
        if (locationClient != null) {
            AMapLocationClientOption option = new AMapLocationClientOption();
            //設(shè)置定位模式
            option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
            //是否使用定位緩存
            option.setLocationCacheEnable(true);
            //GPS優(yōu)先
            option.setGpsFirst(true);
            //網(wǎng)絡(luò)定位超時(shí)時(shí)間
            option.setHttpTimeOut(10000);
        }
        return this;
    }

第四步:開始定位,結(jié)束定位

    /**
     * 開始定位
     */
    public void startLocation(){
        if (locationClient != null)
            locationClient.startLocation();
    }

    /**
     * 結(jié)束定位
     */
    public void stopLocation(){
        if (locationClient != null) {
            locationClient.stopLocation();
            locationClient.onDestroy();
            locationClient = null;
        }
    }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,537評(píng)論 19 139
  • 因?yàn)橐鲆粋€(gè)地圖操作的項(xiàng)目,需要用到這個(gè)地圖庫,但是查詢官方API麻煩,而且這個(gè)地圖框架的API做的用起來確實(shí)太麻...
    虛幻的銹色閱讀 34,253評(píng)論 1 15
  • 最近在做基于高德地圖的定位、導(dǎo)航及添加大頭針的功能,特此記錄下來。。。方便剛接觸的同學(xué)參考。。。 一、申請(qǐng) Key...
    attackGiant閱讀 13,373評(píng)論 50 40
  • 快捷鍵 Ctrl+Shift+Up 向上移動(dòng)行 Ctrl+Shift+Down 向下移動(dòng)行 Ctrl+[ / ] ...
    糖蔥薄餅煎的蛋閱讀 389評(píng)論 0 2
  • 二月,下了春天到來后的第一場(chǎng)雪,也是二零一六年冬天遲來的最后一場(chǎng)雪。 那場(chǎng)雪洋洋灑灑、肆意而豪氣地下了一整天,我走...
    簡(jiǎn)微檸Jean閱讀 525評(píng)論 0 2

友情鏈接更多精彩內(nèi)容