Skip to content

微信小程序——授权位置信息弹框

微信小程序 | August 26, 2020


文章链接:https://blog.csdn.net/qq_43201350/article/details/108248341

1、首先需要在app.json中配置

app.json文件

 
  "permission": {
    "scope.userLocation": {
     "desc": "您的位置信息用于获取当前定位地点" // 提示的文字,可自行定义
  }

js文件

onReady: function () {
    const that = this
    wx.getLocation({
        type: 'wgs84',
        success(res) {
            that.setData({
                latitude: res.latitude,
                longitude: res.longitude
            })
        },
        fail(res) {
            that.setData({
                not_auth: true
            })
        }
    })
}