许多小程序授权的时候 有的会点击取消授权,这就要打开设置重新授权了
onShow() {
this.Autho()
},
//授权
Autho() {
var that = this
uni.authorize({
scope: 'scope.userLocation',
success(res) {
that.lat()
},
// 授权失败
fail(err) {
err = err['errMsg']
uni.showModal({
title: '温馨提示',
content: '为享受小程序功能,您必须授权!',
showCancel: false,
confirmText: '确认授权'
})
.then(res => {
if (res[1]['confirm']) {
uni.openSetting({
success(res) {
}
})
}
})
}
})
},
//获取经纬度
lat() {
var that = this
uni.getLocation({
type: 'wgs84',
success: function(res) {
that.longitude = res.longitude
that.latitude = res.latitude
},
fail: function(res) {
console.log(res);
that.showToast('请检查定位是否已开启')
}
});
},