关于距离计算的问题?
发布于 7 年前 作者 yang47 14645 次浏览 来自 官方Issues
  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>

2 回复

有什么报错吗

值是可以拿到 ,只是setData有问题

回到顶部