微信小程序的wx.getLocation修改data 的数据

代码执行的和预期的不一样。

var that = this;
    wx.getLocation({
      type: 'gcj02',
      success(res) {
        const latitude = res.latitude
        const longitude = res.longitude
        console.log("纬度的值"+latitude+"经度的值"+longitude);
        that.setData({
          longitude,
          latitude
        })
      },
    })
    console.log("纬度的值" + this.data.longitude);
    console.log("经度的值" + this.data.latitude);

img

wx.getLocation是异步的,因为获取需要时间,不阻塞面的代码,先执行了下面的输出。只有成功了才执行,success里的console