// 获取地理位置
getLocation() {
const that = this;
wx.getLocation({
type: "gcj02",
success: (res) => {
const location = {
longitude: res.longitude,
latitude: res.latitude,
}
},
fail: (err) => {
that.authLocation();
},
});
},
// 授权位置
authLocation() {
const that = this;
wx.getSetting({
success: (result) => {
if (
result.authSetting["scope.userLocation"] != undefined &&
result.authSetting["scope.userLocation"] != true
) {
wx.showModal({
title: "提示",
content: "定位未开启,建议开启定位体验更完整的服务",
success: function (res) {
if (res.cancel) {
wx.showToast({
title: "授权失败",
icon: "none",
});
} else if (res.confirm) {
wx.openSetting({
success: function (data) {
// console.log(data);
if (data.authSetting["scope.userLocation"] == true) {
wx.showToast({
title: "授权成功",
icon: "none",
});
//再次授权,调用getLocationt的API
that.getLocation();
} else {
wx.showToast({
title: "授权失败",
icon: "none",
});
}
},
});
}
},
});
}
},
fail: () => { },
complete: () => { },
});
},
小程序地理位置授权
最新推荐文章于 2024-10-02 15:19:42 发布