微信小程序获取用户经纬度信息,用户定位

最近项目有一个需求需要获取用户的经纬度信息,百度后发现用下面的代码就可以获取了,

 
    wx.getLocation({
      type: 'wgs84',
      success: (res) => {
        var latitude = res.latitude
        var longitude = res.longitude
        var speed = res.speed
        var accuracy = res.accuracy
        wx.showModal({
          title: '当前位置',
          content: '经度' + res.longitude + '纬度' + res.latitude,
        })
      }
    })
  }

但是在调用的时候弹窗提示

 
 
随后在app.json中插入以下代码后获取成功
    "permission": {
      "scope.userLocation": {
        "desc": "你的位置信息将用于小程序位置接口的效果展示"
      }
    }

猜你喜欢

转载自www.cnblogs.com/xqz1314/p/11288683.html