//这个函数是一开始点击事件触发的:
export const authorization = async () => {
try {
return await getWxLocation() //等待
} catch (error) {
wx.showModal({
title: '温馨提示',
content: '获取权限失败,需要获取您的地理位置才能为您提供更好的服务!是否授权获取地理位置?',
success: function(res) {
if (res.confirm) { //这里是点击了确定以后
console.log('用户点击确定')
toSetting()
} else { //这里是点击了取消以后
console.log('用户点击取消')
}
}
})
return
}
}
const getWxLocation = () => {
wx.showLoading({
title: '定位中...',
mask: true,
})
return new Promise((resolve, reject) => {
let _locationChangeFn = (res) => {
console.log('location change', res)
resolve(res)
wx.hideLoading()
wx.offLocationChange(_locationChangeFn)
}
wx.startLocationUpdate({
type: 'gcj02',
success: (res) => {
console.log(11,res);
wx.onLocationChange(_locationChangeFn
uniapp频繁调取经纬度地理位置
最新推荐文章于 2024-06-29 09:14:21 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)