微信小程式 相容使用者拒絕獲取位置許可權 使用者拒絕許可權處理
阿新 • • 發佈:2019-01-05
function getAuthor() {
wx.getLocation({
type: 'wgs84',
success: function (res) {
var latitude = res.latitude
var longitude = res.longitude
var speed = res.speed
var accuracy = res.accuracy
}
})
wx.getSetting({
success(res) {
if (!res.authSetting['scope.userLocation' ]) {
openSetting();
}
}
})
}
function openSetting() {
wx.openSetting({
success: (res) => {
if (!res.authSetting['scope.userLocation']) {
showRemind();
}
}, fail: (res) => {
if (!res.authSetting['scope.userLocation']) {
showRemind();
}
}
})
}
function showRemind() {
wx.showModal({
title: '溫馨提醒',
content: '需要獲取您的地理位置才能使用小程式',
showCancel: false,
confirmText: '獲取位置',
success: function (res) {
if (res.confirm) {
getAuthor();
}
},fail: (res) => {
getAuthor();
}
})
}