运行到鸿蒙模拟器返回 getLocation fail maybe not turn on the system location permission无法获取经纬度

运行到鸿蒙模拟器返回 getLocation fail maybe not turn on the system location permission无法获取经纬度

开发环境 版本号 项目创建方式
Windows 22H2 HBuilderX
HarmonyOS 5.0.5 -
模拟器 - DevEco Studio 5.1.1 Release

示例代码:

uni.getLocation({
//type: 'gcj02',
//isHighAccuracy:true,
success: function (res) {
console.log('获取定位:' + res);
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
},
fail: (err) => {
console.error('定位失败', err);

操作步骤:

uni.getLocation({
//type: 'gcj02',
//isHighAccuracy:true,
success: function (res) {
console.log('获取定位:' + res);
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
},
fail: (err) => {
console.error('定位失败', err);

预期结果:

返回经度纬度


### 实际结果:


返回提示errMsg: "getLocation:fail maybe not turn on the system location permission."

bug描述:

调用 uni.getLocation返回问题, 已经按要求在项目 中的harmony-configs 中设置 module.json5与string.json,采用腾讯地图配置了 key(截图5),当运行调用uni.getLocation弹窗出位置权限申请,如附件1权限申请截图,如点击【不允许】返回:定位失败 {errMsg: “getLocation:fail maybe not obtain GPS Permission.”,如点击【本次允许、使用期间允许】返回定位失败 {errMsg: “getLocation:fail maybe not turn on the system location permission.” getLocation:fail maybe not turn on the system location permission,在鸿蒙模拟器中(HarmonyOs 5.1.1(19))中无定位服务,模拟器中的 gps模拟已经手动设置纬度与经度(见截图2gps),模拟器中应用设置了是允许(截图3设置)

网络上查询不到errMsg: "getLocation:fail maybe not turn on the system location permission 的相关文章,现无法获取经纬度,敬请管理员给个相关建议


更多关于运行到鸿蒙模拟器返回 getLocation fail maybe not turn on the system location permission无法获取经纬度的实战教程也可以访问 https://www.itying.com/category-93-b0.html

4 回复

是不是你下拉状态栏的位置权限没有开启?

更多关于运行到鸿蒙模拟器返回 getLocation fail maybe not turn on the system location permission无法获取经纬度的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


就是这个问题。非常感谢,也希望这个坑能分享给其它遇到相同问题的开发者

好的,感谢反馈

这个错误提示表明系统定位服务未开启,即使应用已获得定位权限。在鸿蒙模拟器中,需要额外检查以下配置:

  1. 模拟器定位服务开关:鸿蒙模拟器默认可能关闭系统定位服务。请在模拟器设置中搜索"定位服务"或"位置信息",确保系统级定位开关已开启。

  2. GPS模拟数据验证:虽然你已设置GPS模拟坐标,但需要确认:

    • 坐标格式正确(经度范围-180~180,纬度范围-90~90)
    • GPS模拟服务已正常启动
  3. 权限配置检查:在module.json5中确认已添加位置权限:

"requestPermissions": [
  {
    "name": "ohos.permission.LOCATION"
  }
]
回到顶部