前端Vue騰訊地圖SDK Api經(jīng)緯度解析為地址信息Geocoding 可用于定位經(jīng)緯度信息解析為地址软族,?下載完整代碼請(qǐng)?jiān)L問uni-app插件市場(chǎng)地址:https://ext.dcloud.net.cn/plugin?id=13311
效果圖如下:
# cc-tencentGeocoding
#### 使用方法
```使用方法
// 引入騰訊地圖sdk
import qqmapsdk from "../../utils/qqmap-wx-jssdk.min.js";
// 地址反向編碼解析地址
geocodingClick(e) {
const QQMapWX = new qqmapsdk({
//騰訊地圖? 需要用戶自己去申請(qǐng)key
key: "SFABZ-WANWW-FISRY-3IGTF-HV7RE-YSFTI"
});
let that = this;
QQMapWX.reverseGeocoder({
location: {
latitude: that.locatonDict.lat,
longitude: that.locatonDict.lng
},
success: function(res) {
console.log('解析地址成功', res);
uni.showModal({
title: "解析地址",
content: "解析地址 = " + JSON.stringify(res)
})
that.addressInfo = JSON.stringify(res);
},
fail: function(res) {
console.log(res);
},
complete: function(res) {
console.log(res);
}
});
},
```
#### HTML代碼實(shí)現(xiàn)部分
```html
<template>
<view class="content">
<view style="margin-top: 20px;">{{"經(jīng)度信息 = "? + locatonDict.lng }}</view>
<view style="margin-top: 20px;">{{"緯度信息 = " + locatonDict.lat }}</view>
<!-- 點(diǎn)擊按鈕 地址反向編碼 -->
<button @click="geocodingClick" style="margin: 28px 20px;">解析地址</button>
<!-- 地址信息 -->
<view class="infoView">{{addressInfo}}</view>
</view>
</template>
<script>
// 引入騰訊地圖sdk
import qqmapsdk from "../../utils/qqmap-wx-jssdk.min.js";
export default {
data() {
return {
locatonDict: {
lng: 112.2626,
lat: 23.1578
},
addressInfo: ''
}
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面顯示
*/
onShow: function() {
},
methods: {
// 地址反向編碼解析地址
geocodingClick(e) {
const QQMapWX = new qqmapsdk({
//騰訊地圖? 需要用戶自己去申請(qǐng)key
key: "SFABZ-WANWW-FISRY-3IGTF-HV7RE-YSFTI"
});
let that = this;
QQMapWX.reverseGeocoder({
location: {
latitude: that.locatonDict.lat,
longitude: that.locatonDict.lng
},
success: function(res) {
console.log('解析地址成功', res);
uni.showModal({
title: "解析地址",
content: "解析地址 = " + JSON.stringify(res)
})
that.addressInfo = JSON.stringify(res);
},
fail: function(res) {
console.log(res);
},
complete: function(res) {
console.log(res);
}
});
},
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
}
.infoView {
width: 88%;
font-size: 13px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #333333;
line-height: 20px;
padding: 12px 8px;
background-color: #F6F7F8;
/* 換行 */
white-space: pre-line;
}
</style>
```