onShow: function () {
var that = this;
that.getDistance()
}
getDistance: function () {
var that = this;
let destinationDistance;
demo.calculateDistance({
to: [{
latitude: app.globalData.user.latitude ,
longitude: app.globalData.user.longitude
}],
success: function (res) {
destinationDistance = res.result.elements[0].distance;
let distanceKm = `${(destinationDistance / 1000).toFixed(2)}`;
console.log('DIS',distanceKm)
that.setData({
distance: distanceKm
})
},
fail: function (res) {
console.log('ERROR',res);
}
});
}
<cover-view wx:if="{{address}}">
({{distance}}KM)
</cover-view>
有什么报错吗
值是可以拿到 ,只是setData有问题