微信小程序之地理位置授权 wx.getLocation

时间:2018-11-22 18:17:06   收藏:0   阅读:607

1. 授权地理位置

<button bindtap='onAuthLocation' >授权位置</button>
onAuthLocation() {
    wx.authorize({
        scope: 'scope.userLocation',
        success: (res) => {
            console.log('成功:' , res)
        },
        fail: (res) => {
            console.log('失败:', res)
        },
    })
},

2. 获取地理位置

<button bindtap='onGetLocation' >获取位置</button>
onGetLocation() {
    wx.getLocation({ 
        success: (res) => {
            console.log('成功:', res)
        },
        fail: (res) => {
            console.log('失败:', res)
        },
    })
},

3. 拒绝后再次授权,打开授权面板

<button bindtap='gotoSetting' >打开授权信息面板</button>
gotoSetting() {
    wx.openSetting({
        success: (res) => {
            console.log(res)
        }
    })
},
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!