專屬邀請鏈接: https://lbs.qq.com?lbs_invite=G9MRFLG
專案開始于2021-01-27 晚8uniapp模板地址 https://ext.dcloud.net.cn/plugin?id=4067
github地址 https://github.com/dmhsq/uniapp-txwzsdk-demo
騰訊位置服務牛逼
騰訊位置服務檔案小程式SDK :https://lbs.qq.com/miniProgram/jsSdk/jsSdkGuide/jsSdkOverview案例一:實作 位置共享 https://blog.csdn.net/qq_42027681/article/details/113428833
案例二:實作 運動軌跡記錄 https://blog.csdn.net/qq_42027681/article/details/113429566
在線體驗 (打不開的話可能在審核)
雖然說官方檔案寫的是微信小程式,但是只要是Js其它平臺也應該通用 試了下位元組小程式可以用
在閱讀此文章之前 需要了解 map組件的 部分屬性
| 屬性 | 型別 | 作用 |
|---|---|---|
| longitude | Number | 經度 |
| latitude | Number | 緯度 |
| scale | Number | 縮放級別 |
| markers | Array | 標記的點 |
| polyline | Array | 地圖軌跡 |
| @regionchange | EventHandle | 視野發生變化時觸發 |
| @tap | EventHandle | 點擊地圖觸發的事件 |
整合騰訊位置服務SDK
- 引入SDK檔案
- 實體化核心功能類
- 引入核心類
- 實體化
- 功能接入
- 接入地點搜索
- 關鍵詞輸入提醒
- 逆地址決議(坐標轉地址)
- 地址決議(地址轉坐標)
- 路線規劃
- 距離計算
- 獲取城市串列
- 視頻預告
引入SDK檔案
可以去官網下載 https://lbs.qq.com/miniProgram/jsSdk/jsSdkGuide/jsSdkOverview
下載地址為 https://mapapi.qq.com/web/miniprogram/JSSDK/qqmap-wx-jssdk1.2.zip
根目錄下添加 common 檔案夾

實體化核心功能類
引入核心類
根據自己檔案路徑修改路徑
var QQMapWX = require('../../common/qqmap-wx-jssdk.js')

實體化
var app = new QQMapWX({
key: '騰訊位置服務控制臺獲取'
})
騰訊位置服務控制臺獲取 key

功能接入
說明 : 詳細接入可選引數和回傳引數 請移步官網 https://lbs.qq.com/miniProgram/jsSdk/jsSdkGuide/jsSdkOverview
接入地點搜索
app.search({
//from引數不填默認當前地址//fromPs, 格式為 fromPs:{longitude: num,latitude: num}
keyword: keys, //關鍵詞
locationto: youP, //格式為 youP: `latitude,longitude` 字串 比如: "33.643206,114.851074" 或者物件格式{latitude:xxx,longitude:xxx}
success: res=>{
console.log(res)
}
})


| 屬性 | 型別 | 作用 |
|---|---|---|
| longitude | Number | 地點經度 |
| latitude | Number | 地點緯度 |
| title | Str | 地點名稱 |
| polygon | Array | 地點形狀 |
| cricle | Array | 圓屬性 |
| callout | Array | 點擊標記的顯示屬性 |
關鍵詞輸入提醒
app.getSuggestion({
//from引數不填默認當前地址
keyword: keys,: //關鍵詞
region: city, //可不選,限制搜索城市
success: res=>{
console.log(res.data)
}
})

| 屬性 | 型別 | 作用 |
|---|---|---|
| location.lng | Number | 地點經度 |
| location.lat | Number | 地點緯度 |
| title | Str | 地點名稱 |
| id | Str | 地點id |
| address | Str | 詳細地址 |
| category | Str | 分類 |
| province | Str | 省 |
| city | Str | 市 |
| district | Str | 區縣 |
逆地址決議(坐標轉地址)
demo.reverseGeocoder({
location: fromPs, //格式為 `latitude,longitude` 字串 比如: "33.643206,114.851074" 或者物件格式{latitude:xxx,longitude:xxx}
success: function(res) {
console.log(res.result)
}
})

| 屬性 | 型別 | 作用 |
|---|---|---|
| location.lng | Number | 地點經度 |
| location.lat | Number | 地點緯度 |
| title | Str | 地點名稱 |
| formatted_addresses.rough | Str | 詳細位置 |
| address | Str | 詳細地址 |
| category | Str | 分類 |
| address_component.nation | Str | 國家地區 |
| address_component.province | Str | 省 |
| address_component.city | Str | 市 |
| address_component.district | Str | 區縣 |
| address_component.street | Str | 街道 |
| address_component.street_number | Str | 門牌號 |
| address_reference.town | Str | 鄉鎮 |
| address_reference.landmark_l2 | Str | 村落 |
地址決議(地址轉坐標)
demo.geocoder({
address: address,//地址
success: function(res) {
console.log(res)
vm.doOne(res.result)
}
})
| 屬性 | 型別 | 作用 |
|---|---|---|
| location.lng | Number | 地點經度 |
| location.lat | Number | 地點緯度 |
| title | Str | 地點名稱 |
| formatted_addresses.rough | Str | 詳細位置 |
| address | Str | 詳細地址 |
| category | Str | 分類 |
| address_component.nation | Str | 國家地區 |
| address_component.province | Str | 省 |
| address_component.city | Str | 市 |
| address_component.district | Str | 區縣 |
| address_component.street | Str | 街道 |
| address_component.street_number | Str | 門牌號 |
| ad_info.adcode | Str | 地址編號 |
| similarity | Str | 輸入地址與決議結果誤差(文本相似度) |
| deviation | Str | 誤差距離 |
| reliability | Str | 可信度 越大越可信 |
路線規劃
規劃路線
app.direction({
mode: "" , //driving’(駕車)、‘walking’(步行)、‘bicycling’(騎行)、‘transit’(公交),默認:‘driving’
//from引數不填默認當前地址
from: fromPs, //格式為 fromPs: `latitude,longitude` 字串 比如: "33.643206,114.851074" 或者物件格式{latitude:xxx,longitude:xxx}
to: toPs, //格式為 toPs: `latitude,longitude` 字串 比如: "33.643206,114.851074" 或者物件格式{latitude:xxx,longitude:xxx}
success: res=>{
console.log(res.result.routes)
}
})

| 屬性 | 型別 | 作用 |
|---|---|---|
| mode | Str | 出行方式 |
| distance | Number | 距離 |
| duration | Number | 規劃的時間(包括路況) |
| polyline | Array | 地點路徑 |
距離計算
demo.calculateDistance({
from: fromP, //格式為 `latitude,longitude` 字串 比如: "33.643206,114.851074" 或者物件格式{latitude:xxx,longitude:xxx}
to: toP, //格式為 : `latitude,longitude` 字串 比如: "33.643206,114.851074" 或者物件格式{latitude:xxx,longitude:xxx}
success:res=>{
console.log(res.result.elements)
}
})

| 屬性 | 型別 | 作用 |
|---|---|---|
| from | Obj | 出發點 |
| to | Obj | 到達點 |
| distance | Number | 距離 |
獲取城市串列
demo.getCityList({
success: res => {
console.log(res.result)
}
})


| 屬性 | 型別 | 作用 |
|---|---|---|
| 0/1/2 | 陣列下標 | 0省級,1市級,2區縣級 |
| 屬性 | 型別 | 作用 |
|---|---|---|
| id | Str | 城市編號 |
| name | Str | 城市簡稱 |
| fullname | Str | 城市全稱 |
| pinyin | Array | 城市拼音 |
| location.lng | Number | 地點經度 |
| location.lat | Number | 地點緯度 |
| cidx | Array | 下級行政區在下個陣列中的下標 |
cidx說明 比如 北京 cidx[015]
那么在市級陣列 他的子行政區下標為0~15的

視頻預告
uniapp整合騰訊位置服務開發小程式位置服務---One---開題及預告
??大家好,我是代碼哈士奇,是一名軟體學院網路工程的學生,因為我是“狗”,狗走千里吃肉,想把大學期間學的東西和大家分享,和大家一起進步,但由于水平有限,博客中難免會有一些錯誤出現,有紕漏之處懇請各位大佬不吝賜教!博客主頁:https://blog.csdn.net/qq_42027681,
騰訊云+社區專欄https://cloud.tencent.com/developer/column/90853
未經本人允許,禁止轉載

后續會推出
前端:vue入門 vue開發小程式 等
后端: java入門 springboot入門等
服務器:mysql入門 服務器簡單指令 云服務器運行專案
python:推薦不溫卜火 一定要看哦
一些插件的使用等
大學之道亦在自身,努力學習,熱血青春
如果對編程感興趣可以加入我們的qq群一起交流:974178910

有問題可以下方留言,看到了會回復哦
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/254790.html
標籤:其他
下一篇:服務注冊中心:Eureka

