//先会获取用户是否授权了定位,如果没有就请求授权,如果用户点了拒绝,就弹窗警告,
wx.getSetting({
success(res) {
if (!res.authSetting['scope.userLocation']) {
wx.authorize({
scope: 'scope.userLocation',
success() {
wx.getLocation({
type: 'wgs84',
success(res) {
const latitude = res.latitude
const longitude = res.longitude
const speed = res.speed
const accuracy = res.accuracy
console.log(res)
}
})
},
fail(err) {
wx.showModal({
title: '警告',
content: '你取消了授权获取位置,这将使你看不到附近商家',
cancelText:'不授权',
confirmText:'授权',
confirmColor:'#0094ff',
success(res) {
if (res.confirm) {
wx.openSetting({
success(res) {
console.log(res)
}
})
}
}
})
}
})
}else{
wx.getLocation({
type: 'wgs84',
success(res) {
const latitude = res.latitude
const longitude = res.longitude
const speed = res.speed
const accuracy = res.accuracy
},
fail(err){
wx.showModal({
title: '警告',
content: '你取消了授权获取位置,这将使你看不到附近商家',
cancelText: '不授权',
confirmText: '授权',
confirmColor: '#0094ff',
success(res) {
if (res.confirm) {
wx.openSetting({
success(res) {
console.log(res)
}
})
}
}
})
}
})
}
}
})