华为meat60pro uni-app uni.getLocation 获取定位失败

华为meat60pro uni-app uni.getLocation 获取定位失败

开发环境 版本号 项目创建方式
Windows win11 HBuilderX

测试过的手机:

鸿蒙OS 4.x

操作步骤:

  • 当用户手动关闭WIFI开关之后,正常获取到定位信息;重新打开WIFI,但未连接WIFI时,重新报错上面信息

预期结果:

实际结果:

bug描述:

当华为的鸿蒙系统手机在打开WIFI的情况下,未连接WIFI,但是使用的是手机卡进行上网,会导致触发:

["errMsg":"getLocation:fail[geolocation:6]定位结果错误 请到http://lbs.amap.com/api/android-location-sdk/guide/utilities/errorcode/查看错误码说明,错误详细信息:#id:xxxxxx==#csid:xxxxxxxxlocation faile retype.rdesc:78#0601#pm110011"}

当用户手动关闭WIFI开关之后,正常获取到定位信息;重新打开WIFI,但未连接WIFI时,重新报错上面信息


更多关于华为meat60pro uni-app uni.getLocation 获取定位失败的实战教程也可以访问 https://www.itying.com/category-93-b0.html

7 回复

稳定复现吗?测试过其它手机吗?

更多关于华为meat60pro uni-app uni.getLocation 获取定位失败的实战教程也可以访问 https://www.itying.com/category-93-b0.html


我们公司的华为Mate60pro是稳定触发,根据离线打包的高德SDK配置的:https://ask.dcloud.net.cn/question/199629

作者的回复:暂时解决了,不停的尝试发现implementation ‘com.amap.api:3dmap:10.0.600’ ,implementation 'com.amap.api:search:9.5.0’这个组合就正常了

回复 2***@qq.com: 感谢反馈,这个应该是高德的问题,按理来说是不需要关注这个的。

多大比例的鸿蒙 4 用户反馈问题,其他机型是否正常,你标准基座空项目,打个自定义基座是否正常。根据报错日志自己排除问题,报错来自地图内部 https://lbs.amap.com/api/android-location-sdk/guide/utilities/errorcode/

基本上华为鸿蒙4.2以上都会有这个问题,但是mate60pro是稳定触发

这是一个典型的定位服务冲突问题,主要出现在华为鸿蒙系统上。当WIFI开关开启但未连接时,系统定位服务可能优先尝试通过WIFI网络定位,而此时实际使用的是移动数据网络,导致定位服务混淆。

解决方案:

  1. 检查定位权限配置 确保manifest.json中已正确配置高德或百度等定位服务商密钥,并在App权限设置中开启定位权限。

  2. 优化定位参数 在调用uni.getLocation时指定type参数:

    uni.getLocation({
      type: 'gcj02',
      highAccuracyExpireTime: 4000, // 高精度定位超时时间
      isHighAccuracy: false, // 非高精度模式
      success: (res) => {},
      fail: (err) => {}
    });
    
  3. 处理定位失败重试机制

    let retryCount = 0;
    const getLocationWithRetry = () => {
      uni.getLocation({
        success: (res) => {},
        fail: (err) => {
          if (retryCount < 3) {
            retryCount++;
            setTimeout(getLocationWithRetry, 1000);
          }
        }
      });
    };
    
  4. 检测网络状态 在定位前先检测网络连接状态:

    uni.getNetworkType({
      success: (res) => {
        if (res.networkType !== 'none') {
          // 执行定位
        }
      }
    });
回到顶部