// 实时定位取坐标
const locationChange = (res2) => {
console.log(res2.longitude + "," + res2.latitude)
uni.showModal({
title: "定位更新了",
content: res2.longitude + "," + res2.latitude,
showCancel: false,
confirmText: "确定",
success: function (res) {},
})
}
// 实时定位请求错误
const locationChangeError = () => {
uni.stopLocationUpdate()
}
onShow(()=>{
uni.startLocationUpdate({
type: "gcj02",
success: (res) => {
uni.onLocationChange(locationChange)
uni.onLocationChangeError(locationChangeError)
},
fail: (err) => {
},
complete: (msg) => {
console.log("调用开启小程序接收位置消息 API 完成")
},
})
}) ```

- 发布:2025-05-29 17:18
- 更新:2025-05-29 17:53
- 阅读:43
【报Bug】 uni.onLocationChange 方法回调在ios系统不持续执行,只有从后太切前台执行一次
产品分类: uniapp/App
PC开发环境操作系统: Mac
PC开发环境操作系统版本号: 15.2 (24C101)
HBuilderX类型: 正式
HBuilderX版本号: 4.66
手机系统: iOS
手机系统版本号: iOS 18
手机厂商: 苹果
手机机型: iphone13
页面类型: vue
vue版本: vue3
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
操作步骤:
上述代码可以复现
上述代码可以复现
预期结果:
预期回调会持续执行拿到回调
预期回调会持续执行拿到回调
实际结果:
uni.onLocationChange() 回调不执行 只有从后台切到前台时 会执行一次
uni.onLocationChange() 回调不执行 只有从后台切到前台时 会执行一次
8***@qq.com (作者)
苹果还需要授权什么么 方便告诉下么 我配置了权限和模块
2025-05-30 08:31