华为手机鸿蒙4.0,微信小程序获取定位获取不到,偶尔可以成功,ios没问题,失败的时候有时候只打印个start,有时候start也不打印
onShow(){
this.glApp.doLocation((res) => {
this.getList();
})
}
export const doLocation = (completed) => {
console.log("start")
uni.getLocation({
isHighAccuracy: true,
type: 'gcj02',
success(res) {
console.log("succcc")
uni.setStorageSync('locMess', res)
completed(res)
},
fail(res) {
console.log("errrr")
//+'('+(typeof res === 'object'?res.errMsg:res)+')'
uni.removeStorageSync('locMess')
uni.hideLoading()
uni.getSetting({
success(res) {
console.log(res.authSetting)
if (res.authSetting['scope.userLocation'] == false) {
uni.showModal({
title: '温馨提示',
content: '定位失败,请开启定位',
cancelText: '取消',
confirmText: '去开启',
success: function(res) {
if (res.confirm) {
uni.openSetting({
scope: 'scope.userLocation'
})
} else if (res.cancel) {
completed()
}
}
});
} else {
uni.showToast({
icon: "none",
title: '定位失败,请检查设置',
duration: 2000,
success() {
completed()
},
fail() {
completed()
}
})
}
}
})
}
})
}
尝试直接用小程序自己的API wx.getLocation() 来获取定位试试看?
不用
uni-app
提供的 uni.getLocation(),先排除是否是uni-app
的问题。