uni-app iOS APP端在版本ios13.3下无法获取定位

uni-app iOS APP端在版本ios13.3下无法获取定位

示例代码:

uni.getLocation({
type: ‘wgs84’,
success: function (res) {
console.log(‘当前位置的经度:’ + res.longitude);
console.log(‘当前位置的纬度:’ + res.latitude);
}
});


## 操作步骤:
- 使用即复现

## 预期结果:
- 正常显示

## 实际结果:
- 正常显示

## bug描述:
mac系统ios模拟器定位获取值不正确,https://hellouniapp.dcloud.net.cn/pages/API/get-location/get-location在手机浏览器正常,项目编译到h5也可以正常获取位置,只有ios APP端不行获取的经度为负数,维度也不正确。plus.geolocation也是一样的结果。代码为文档api复制的代码。

![Image](https://www.itying.com/uniimg.php?url=https://img-cdn-tc.dcloud.net.cn/uploads/questions/20210220/cb6a53a9fdaba029081f2771c4044d39.png)
![Image](https://www.itying.com/uniimg.php?url=https://img-cdn-tc.dcloud.net.cn/uploads/questions/20210220/ea8b8d8b2ac72043376b194be9dc215c.png)

| 信息类别       | 信息内容           |
|----------------|--------------------|
| 产品分类       | uniapp/App         |
| PC开发环境     | Mac                |
| PC开发环境版本 | 11                 |
| HBuilderX类型  | 正式               |
| HBuilderX版本  | 3.1.3              |
| 手机系统       | iOS                |
| 手机系统版本   | iOS 13.4           |
| 手机厂商       | 模拟器             |
| 手机机型       | 模拟器 13.3所有记性|
| 页面类型       | vue                |
| 打包方式       | 云端               |
| 项目创建方式   | HBuilderX          |

更多关于uni-app iOS APP端在版本ios13.3下无法获取定位的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

用真机测试吧,模拟器没有gps,需要手动配置坐标,具体百度一下吧

更多关于uni-app iOS APP端在版本ios13.3下无法获取定位的实战教程也可以访问 https://www.itying.com/category-93-b0.html


针对iOS 13.3模拟器定位问题,以下是关键分析:

  1. 模拟器定位机制差异:
  • iOS模拟器默认使用固定模拟位置(美国苹果总部坐标)
  • 获取到负值经度(-122.031…)是模拟器的预设值,属正常现象
  1. 真机测试建议:
  • 必须使用真机测试定位功能
  • 模拟器无法模拟真实GPS数据
  1. 配置检查要点:
  • 确认manifest.json已配置定位权限:
"ios": {
    "permissions": {
        "LOCATION_ALWAYS": "描述",
        "LOCATION_WHEN_IN_USE": "描述"
    }
}
  1. 代码调试建议:
// 增加fail回调查看错误信息
uni.getLocation({
    type: 'wgs84',
    success: (res) => {
        console.log('定位结果:', res)
    },
    fail: (err) => {
        console.error('定位失败:', err)
    }
})
回到顶部