js:
onLoad: function () {
// 获取位置
var that = this;
// 实例化腾讯地图API核心类
qqmapsdk = new QQMapWX({
key: 'PKYBZ-EB4RQ-KBF5P-GMINL-C6FXK-FHBNI' // 必填
});
wx.getLocation({
type: 'wgs84',
success: function (res) {
that.setData({
latitude:res.latitude,
longitude:res.longitude
})
//2、根据坐标获取当前位置名称,显示在顶部:腾讯地图逆地址解析
qqmapsdk.reverseGeocoder({
location: {
latitude: res.latitude,
longitude: res.longitude
},
success: function (e) {
var location = e.result.address;
console.log("add="+location)
(为什么这一段不会打印)
that.setData({
location: location
})
}
})
// console.log("res==" + app.globalData.latitude)
// console.log("res==" + app.globalData.longitude)
that.setData({
ldata: true,
// latitude: latitude,
// longitude: longitude
})
},
fail: function (res) {
console.log('拒绝授权')
that.setData({
ldata: false
})
}
})
},
btnTap(e) {
console.log("e+" + this.data.latitude + "," + this.data.longitude)
wx.openLocation({
latitude: this.data.latitude,
longitude: this.data.longitude,
scale: 50
})
},
wxml:
<button wx:if="{{ldata}}" bindtap='btnTap' plain='true' type="primary" size="{{mini}}" loading="{{loading}}"
plain="{{plain}}" disabled="{{disabled}}">查看当前位置</button>
<button wx:else open-type="openSetting" bindopensetting='handler' plain='true' type="primary"
size="{{mini}}" loading="{{loading}}"
plain="{{plain}}" disabled="{{disabled}}">点击授权并获取位置信息</button>
能否来个大佬看看呢,不知道咋办呀