前端Vue騰訊地圖SDK Api經緯度決議為地址資訊Geocoding 可用于定位經緯度資訊決議為地址, 下載完整代碼請訪問uni-app插件市場地址: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({
//騰訊地圖 需要用戶自己去申請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代碼實作部分
<template>
<view >
<view style="margin-top: 20px;">{{"經度資訊 = " + locatonDict.lng }}</view>
<view style="margin-top: 20px;">{{"緯度資訊 = " + locatonDict.lat }}</view>
<!-- 點擊按鈕 地址反向編碼 -->
<button @click="geocodingClick" style="margin: 28px 20px;">決議地址</button>
<!-- 地址資訊 -->
<view >{{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: ''
}
},
/**
* 生命周期函式--監聽頁面顯示
*/
onShow: function() {
},
methods: {
// 地址反向編碼決議地址
geocodingClick(e) {
const QQMapWX = new qqmapsdk({
//騰訊地圖 需要用戶自己去申請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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/556552.html
標籤:其他
上一篇:記錄--多行標簽超出展開折疊功能
下一篇:返回列表