使用百度的BDSDK來定位城市

2021-06-28 14:37:04 字數 4047 閱讀 9601

有了這個listener之後,我們來建立出發位址請求的client:

12

3

4

5

6

7

8

9

10

11

12

13

14

public

locationclient

locationclient

=null;

public

bdlocationlistener

mylistener

=new

coolbeetlelocationlistener()

; locationclient

=new

locationclient

(this

.getactivity()

.())

;// 宣告locationclient類

locationclient

.registerlocationlistener

(mylistener);

locationclientoption

option

=new

locationclientoption()

; option

.setopengps

(true);

option

.setaddrtype

("all");

option

.setcoortype

("bd09ll");

option

.setscanspan

(3000);

option

.disablecache

(false);

option

.setpriority

(locationclientoption

.networkfirst);

// 網路定位優先

locationclient

.setlocoption

(option);

// 使用設定

locationclient

.start()

;// 開啟定位sdk

locationclient

.requestlocation()

;// 開始請求位置

上面的請求**可以直接放在activity或者fragement的oncreate 方法中來使用。

記得在activity或者fragment的ondestroy方法中加上關閉請求的**實現:

12

3

4

5 if

(locationclient

!=null

&&locationclient

.isstarted()

) this entry was posted in 

android 小技巧 and tagged 

android百度定位

android value 請輸入你的ak值 由於是第三方定位 直接上 定位sdk監聽函式 public class mylocationlistenner implements bdlocationlistener mylocationdata locdata new mylocationdata...

百度定位API

使用eclipse開發的開發者,只需要將so的資料夾放到libs下即可 使用androidstutio的開發者除了上述操作,還需要在build.gradle中配置so的使用,如下所示 sourcesets 宣告使用許可權 key 開發者申請的keyimport相關類 import com.baidu...

android 百度sdk之 百度定位

步驟 1.控制台建立應用。2.sha1獲得 注意 debug 版本和release不同。debug版本獲取 首先 到c user android目錄下,我的是 c users admin android 其次 在這個目錄下,用cmd.輸入keytool v list keystore debug.k...