2***@qq.com
2***@qq.com
  • 发布:2025-10-29 16:55
  • 更新:2025-10-29 16:55
  • 阅读:15

【报Bug】uniapp 华为手机 harmony os 4.2.0 uni.getLocation 获取到的经纬度是0

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: Windows 10 专业版(21H2)(19044.1682)

HBuilderX类型: 正式

HBuilderX版本号: 4.75

手机系统: Android

手机系统版本号: Android 13

手机厂商: 华为

手机机型: nova 7(HarmonyOS 4.2.0)

页面类型: vue

vue版本: vue2

打包方式: 云端

项目创建方式: HBuilderX

App下载地址或H5⽹址: https://www.pgyer.com/cdf2b88f83cd2c818be36b29400ee028

操作步骤:

安装app,点击左上角进入选择地址页面

预期结果:

预期定位uni.getLocation获取到经纬度;通过经纬度解析得到当前地理位置;显示在页面上

实际结果:

实际定位uni.getLocation获取的经纬度为0;导致无法通过经纬度解析地理位置

bug描述:

uniapp 华为手机 harmony os 4.2.0 uni.getLocation 获取到的经纬度是0
高德和腾讯地图都配置了;

                    let that = this;  
                    uni.getLocation({  
                        type: "gcj02",  
                        geocode: true,  
                        success: function(res) {  
                            utils.showToast("定位信息"+JSON.stringify(res))  
                            uni.request({  
                                url: that.$http.baseUrl + that.$API.postHome_geocode(),  
                                data: {  
                                    event: `${res.latitude},${res.longitude}`,  
                                },  
                                method: 'GET',  
                                success: function(res) {  
                                    // console.log(res);  
                                    if (res.data.data.status == 1) {  
                                        // console.log('反解析结果:', res.data.data.regeocode.addressComponent.city);  
                                        var temCity = res.data.data.regeocode.addressComponent.city;  
                                        var temProvince = res.data.data.regeocode.addressComponent.province;  
                                        temCity = temCity ? (typeof temCity == 'string' ? temCity : temProvince) : "定位失败";  
                                        that.storageCity(temCity);  

                                        setTimeout(function() {  
                                            that.showAlert = false;  
                                        }, 1200);  

                                    } else {  
                                        console.error('反解析失败:', res.data);  
                                    }  
                                },  
                                fail: function(err) {  
                                    console.error('请求失败:', err);  
                                }  
                            });  

                        },  
                        fail: (err) => {  
                            // 这里可以根据errMsg进一步判断,但需要注意errMsg可能因平台差异而有所不同  
                            if (err.errMsg === "getLocation:fail:permission denied") {  
                                utils.showToast("没有定位权限!")  
                                console.log('没有定位权限');  
                            } else if (err.errMsg.includes("getLocation:fail")) {  
                                utils.showToast("定位服务可能未开启或存在其他问题!")  
                                console.log('定位服务可能未开启或存在其他问题');  
                            }  
                            // utils.showToast("定位错误"+JSON.stringify(err))  

                            that.storageCity('定位失败');  
                        }  
                    })
2025-10-29 16:55 负责人:无 分享
已邀请:

要回复问题请先登录注册