废话不多说直接撸代码看图
js代码
map: function (e) {
let that = this //提前声明this,如果不提前声明 success会找不this的指向
wx.getLocation({
type: 'gcj02', //返回可以用于wx.openLocation的经度
success:function(res){
that.setData({
latitude:res.latitude,
longitude:res.longitude
})
wx.openLocation({
latitude: 23.362490,
longitude: 116.715790,
scale: 10,
name:"衡阳",
address:"我在老地方等你"
})
},
当然如果你不提前声明this,我们可以用箭头函数
map: function (e) {
let that = this
wx.getLocation({
type: 'gcj02', //返回可以用于wx.openLocation的经度
success:(res)=>{
this.setData({ //写上箭头函数this就指向全局啦,就可以修改data中的数据了
latitude:res.latitude,
longitude:res.longitude
})
wx.openLocation({
latitude: 23.362490,
longitude: 116.715790,
scale: 10,
name:"衡阳",
address:"我在老地方等你"
})
},
第一次写文章写的不好,不喜勿喷