新手问题,如何显示当前经纬度在<text>
发布于 6 年前 作者 junshi 2539 次浏览 来自 问答

我想把wx.getLocation获得的经纬度填在<text class=“log-item”>{{address}}</text>里面,

在回调函数中this.setData({ address: addr})这样写诗错的,请指正,该如何写?


<view class=“container log-list”>

    <text class=“log-item”>{{address}}</text>

</view>

Page({
   
  onLoad: function () {
    
 
    wx.getLocation({
      success: function (res) {
        var latitude = res.latitude // 经度
        var longitude = res.longitude // 纬度
        var addr = "latitude=" + latitude + ",longitude" + longitude
        console.log(addr)
        //这里出错了,应该是this的问题,但如何表达呢?
        this.setData({ address: addr})
      },
    })
 
  }
1 回复

外面 var that=this 然后 that

回到顶部