首先要到騰訊位置服務(wù)做以下幾步操作:
image.png
然后在你的頁(yè)面中寫入:
let QQMapWX = require('../../utils/qqmap-wx-jssdk.min');//引入第三方sdk
let qqmapsdk;
// 實(shí)例化騰訊地圖API核心類
qqmapsdk = new QQMapWX({
key: '你申請(qǐng)的密鑰' // 必填
});
接下來(lái)坛掠,比如說你打算在 onLoad
的時(shí)候直接請(qǐng)求用戶位置:
onLoad() {
// 獲取地理位置
let _this = this;
wx.getLocation({
success(res){
_this.getLocal(res.latitude, res.longitude)
}
})
},
getLocal: function (latitude, longitude) {
let that = this;
qqmapsdk.reverseGeocoder({
location: {
latitude: latitude,
longitude: longitude
},
success: function (res) {
console.log(res);
let province = res.result.ad_info.province
that.setData({
province: province,
})
}
});
}
如此便可以得到用戶所在的具體位置躬存。