這篇文章將為大家詳細講解有關微信小程序獲取地址的實現方法,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
微信小程序獲取地址的具體代碼如下

wxml
<map id="map" longitude="{{data.longitude}}" latitude="{{data.latitude}}" scale="14" markers="{{markers}}" polyline="{{polyline}}" show-location ></map>
<text>
{{data.longitude}}
{{data.latitude}}
{{address}}
</text>
<!-- longitude 中心經度 -->
<!-- latitude 中心緯度 -->
<!-- scale 縮放級別,取值范圍為3-20 -->
<!-- markers 標記點 -->js
var QQMapWX = require('../js/qqmap-wx-jssdk.js');
var qqmapsdk;
Page({
data:{
data:"",
str:"",
address:""
},
onLoad: function () {
let _this = this;
// 實例化API核心類
qqmapsdk = new QQMapWX({
key: 'key'
});
// Promise 獲取地址
let gets = new Promise((resolve, reject) => {
wx.getLocation({
type: 'wgs84',
success:resolve
})
}).then(function(res){
console.log(res)
_this.setData({
data:res
})
})
// 正常方式獲取地址
wx.getLocation({
type: 'wgs84',
success:function(res){
_this.setData({
str: _this.res
})
console.log(res)
var demo = new QQMapWX({
key: 'key'
});
// 解析地址
demo.reverseGeocoder({//地址解析
location: {
latitude: res.latitude,
longitude: res.longitude
},
success: function (res) {//轉為具體地址
console.log(res);
//獲得地址
_this.setData({
address: res.result.address
})
},
fail: function (res) {
console.log(res);
}
});
}
})
},關于“微信小程序獲取地址的實現方法”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。