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);
}
});
}
})
},
|