小程序地图导航中的经纬如何获取DATA中的值?
大牛们好,小白想做一个可以在管理后台设置地图导航的位置(像多用户商城中各店铺有自己的导航,经纬值都不一样。),想通过外部接口赋值到data中,再赋值到wx.openLocation中的latitude、longitude,但不知道该怎么写,如何获取data中的值?请大牛们多多指教,感谢!
Page({
data: {
detail: {
id: 1,
tel: '0769-88888888',
lat: '23.019080', //想获取的值
lng: '113.747950', //想获取的值
},
bol: true
},
calling: function () {
wx.makePhoneCall({
phoneNumber: this.data.detail.tel, //可正常获取data.detail.tel值
success: function () {
console.log("致电话成功!")
},
fail: function () {
console.log("致电话失败!")
}
})
},
openMap: function () {
wx.getLocation({
type: 'gcj02', //返回可以用于wx.openLocation的经纬度
success: function (res) {
var latitude = res.latitude //当前值需保留
var longitude = res.longitude //当前值需保留
wx.openLocation({
latitude: //这里该如何写才能获取data.detail.lat值?,
longitude: //这里该如何写才能获取data.detail.lng值?,
//这里使用this.data.detail.xxx无法获取
scale: 28
})
}
})
},
onLoad: function (options) {
//console.log('onLoad')
var that = this
wx.request({
url: 'http://localhost/luopan/index.php?s=/addon/Luopan/Luopan/getDetail', //外部接口获取data,detail下的数值
data: { id: options.id },
header: {
'content-type': 'application/json'
},
success: function (res) {
console.log(res.data)
that.setData({
detail: res.data
})
}
})
}
})