微信小程序获取定位问题?

华为手机鸿蒙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()
                            }

                        })
                    }
                }
            })
        }
    })
}
阅读 898
1 个回答

尝试直接用小程序自己的API wx.getLocation() 来获取定位试试看?
不用 uni-app 提供的 uni.getLocation(),先排除是否是 uni-app 的问题。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题