使用uni自带的方法:uni.getLocation(OBJECT)
let setTime = setInterval(() => {
uni.getLocation({
type: 'wgs84',
success(res) {
clearInterval(setTime)
console.log('开启定位权限',res);
},
fail: (err) => {
console.log('请确认打开定位功能');
}
});
}, 3000)
每隔3秒可以获取一次位置坐标来变相的获取定位权限
但是在pad打包之后,这个方法有时会一直失败,就算开启定位权限也会失败, 现在还不知道哪里有问题。