uni.chooseLocation({
success: (res) => {
// console.log(res);
let distance = this.algorithm(jwdlist, {
x2: res.longitude,
y2: res.latitude
})
// console.log("距离,", distance)
// this.form.SCCSDZ = res.address + res.name
this.form.QDDZ = res.address + res.name
this.form.JD = Number(res.longitude.toFixed(8));
this.form.WD = Number(res.latitude.toFixed(8));
this.form = JSON.parse(JSON.stringify(this.form));
},
fail: (res) => {
uni.showToast({
title: res,
icon: "none",
});
console.log("定位失败", res)
},
complete: () => {
this.JWDLoading = false;
},
});

- 发布:2022-08-23 17:17
- 更新:2022-08-23 17:40
- 阅读:385
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: window10
HBuilderX类型: 正式
HBuilderX版本号: 3.5.3
手机系统: Android
手机系统版本号: Android 12
手机厂商: 小米
手机机型: Redmi K50
页面类型: vue
vue版本: vue2
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
操作步骤:
uni.chooseLocation({
success: (res) => {
// console.log(res);
let distance = this.algorithm(jwdlist, {
x2: res.longitude,
y2: res.latitude
})
// console.log("距离,", distance)
// this.form.SCCSDZ = res.address + res.name
this.form.QDDZ = res.address + res.name
this.form.JD = Number(res.longitude.toFixed(8));
this.form.WD = Number(res.latitude.toFixed(8));
this.form = JSON.parse(JSON.stringify(this.form));
},
fail: (res) => {
uni.showToast({
title: res,
icon: "none",
});
console.log("定位失败", res)
},
complete: () => {
this.JWDLoading = false;
},
});
uni.chooseLocation({
success: (res) => {
// console.log(res);
let distance = this.algorithm(jwdlist, {
x2: res.longitude,
y2: res.latitude
})
// console.log("距离,", distance)
// this.form.SCCSDZ = res.address + res.name
this.form.QDDZ = res.address + res.name
this.form.JD = Number(res.longitude.toFixed(8));
this.form.WD = Number(res.latitude.toFixed(8));
this.form = JSON.parse(JSON.stringify(this.form));
},
fail: (res) => {
uni.showToast({
title: res,
icon: "none",
});
console.log("定位失败", res)
},
complete: () => {
this.JWDLoading = false;
},
});
预期结果:
出现获取定位失败应该走fail报错
出现获取定位失败应该走fail报错
实际结果:
没有报错
没有报错
CODE_XU
真机调试也无法定位吗?
2022-08-23 18:56
1***@qq.com (作者)
回复 CODE_XU: 真机可以,但真机测试机型比较少,打包后小米第一次进入时,时常获取不到自身位置并且列表没有数据
2022-08-25 18:35
1***@qq.com (作者)
回复 CODE_XU: 这是云打包的问题吗
2022-08-30 10:38
CODE_XU
回复 1***@qq.com: 其他设备也会出现此问题吗?
2022-08-30 11:13
1***@qq.com (作者)
回复 CODE_XU: 小米系列手机,红米出现这种问题较多,其他一加、华为没出现这种问题,之前也换过高德的key了,还是会有这种问题,发生挺频繁的
2022-08-30 18:28
CODE_XU
回复 1***@qq.com: 有没有可能是权限的问题,确保已经获取到权限之后再调用试一下
2022-08-30 18:31
1***@qq.com (作者)
回复 CODE_XU: 如果权限有问题不应该一开始就拿不到定位吗?怎么会有时获取得到有时不行,最近真机调试中也发现了会出现定位获取不到的问题,这次不是小米手机,用的一加
2022-09-01 15:00
CODE_XU
回复 1***@qq.com: 获取不到的时候,重新获取也取不到吗?有没有报错
2022-09-01 15:03
1***@qq.com (作者)
我尝试将报错打印到数据库,获取不到时并没有报错
2022-09-01 15:33
1***@qq.com (作者)
回复 CODE_XU: 没有报错,获取不到的时候,重新进入也是获取不到,卡在天安门,需要关闭程序重新打开才能在获取到
2022-09-01 15:34