uni.getSetting({
success: (res) => {
if (!res.authSetting['']) {
console.log("没有权限");
//拉取授权窗口
uni.authorize({
scope: "",
success: () => {
uni.getLocation({
type: 'gcj02',
success: (res) => {
console.log("获取当前位置的接口", res);
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
qqmapsdk.reverseGeocoder({
location: {
latitude: res.latitude,
longitude: res.longitude
},
success: (res) => {
console.log("位置:", res)
// 调用打卡接口
let obj = {
address: res.result
.formatted_addresses
.standard_address,
longitude_x: res
.result
.location.lng,
latitude_y: res
.result
.location.lat
}
sign_in(obj, 'POST').then(
res => {
if (res.code ==
200) {
uni.showToast({
title: "打卡成功!",
icon: "success"
})
}
})
}
})
}
});
},
fail: (err) => {
uni.showModal({
title: '提示',
content: '若点击不授权,将无法使用位置功能',
cancelText: '不授权',
cancelColor: '#999',
confirmText: '授权',
confirmColor: '#f94218',
success: (res) => {
if (res.confirm) {
uni.openSetting({
success: (res) => {
console.log(res
.authSetting);
}
})
} else if (res.cancel) {
console.log("用户点击不授权");
}
}
})
}
})
} else {
//有权限直接获取
uni.getLocation({
type: 'wgs84',
success: (res) => {
console.log("获取当前位置的接口", res);
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
qqmapsdk.reverseGeocoder({
location: {
latitude: res.latitude,
longitude: res.longitude
},
success: (res) => {
console.log("位置:", res)
let obj = {
address: res.result.formatted_addresses
.standard_address,
longitude_x: res.result.location.lng,
latitude_y: res.result.location.lat
}
sign_in(obj, 'POST').then(res => {
if (res.code == 200) {
uni.showToast({
title: "打卡成功!",
icon: "success"
})
}
})
}
})
}
});
}
}
})