|
|
@@ -825,6 +825,10 @@ export default {
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+ // 声明变量在外部作用域,确保finally块可以访问
|
|
|
+ let formattedAddress = '';
|
|
|
+
|
|
|
// 调用高德sdk 逆地理编码
|
|
|
try {
|
|
|
// 调用后台API进行逆地理编码
|
|
|
@@ -838,11 +842,16 @@ export default {
|
|
|
});
|
|
|
|
|
|
if (geocodingResponse.code === 200 && geocodingResponse.data) {
|
|
|
- const formattedAddress = geocodingResponse.data.regeocode?.formattedAddress;
|
|
|
+ formattedAddress = geocodingResponse.data.regeocode?.formattedAddress || '';
|
|
|
if (formattedAddress) {
|
|
|
console.log('逆地理编码成功:', formattedAddress);
|
|
|
// 可以选择将地址信息显示给用户或保存到表单中
|
|
|
// this.form.leaveLocationAddress = formattedAddress; // 如果需要保存地址信息
|
|
|
+ uni.showToast({
|
|
|
+ title: formattedAddress,
|
|
|
+ icon: 'none',
|
|
|
+ duration: 2000,
|
|
|
+ });
|
|
|
}
|
|
|
} else {
|
|
|
console.warn('逆地理编码失败:', geocodingResponse.msg);
|
|
|
@@ -850,23 +859,32 @@ export default {
|
|
|
} catch (error) {
|
|
|
console.error('逆地理编码请求失败:', error);
|
|
|
// 逆地理编码失败不影响地图打开功能
|
|
|
- }
|
|
|
+ } finally {
|
|
|
+ console.log('=== finally块开始执行 ===');
|
|
|
+ console.log('formattedAddress:', formattedAddress);
|
|
|
+ console.log('isWechatBrowser:', this.isWechatBrowser);
|
|
|
+ console.log('wechatSDK.isInitialized:', this.wechatSDK?.isInitialized);
|
|
|
|
|
|
- if (this.isWechatBrowser && this.wechatSDK.isInitialized) {
|
|
|
- try {
|
|
|
- await this.wechatSDK.openLocation({
|
|
|
- latitude: latitude,
|
|
|
- longitude: longitude,
|
|
|
- name: formattedAddress,
|
|
|
- address: this.form.leaveLocation || '当前位置',
|
|
|
- scale: 16,
|
|
|
- });
|
|
|
- } catch (error) {
|
|
|
- console.error('微信地图打开失败:', error);
|
|
|
+ if (this.isWechatBrowser && this.wechatSDK?.isInitialized) {
|
|
|
+ try {
|
|
|
+ console.log('尝试使用微信SDK打开地图...');
|
|
|
+ await this.wechatSDK.openLocation({
|
|
|
+ latitude: latitude,
|
|
|
+ longitude: longitude,
|
|
|
+ name: formattedAddress || '请假位置',
|
|
|
+ address: formattedAddress || '当前位置',
|
|
|
+ scale: 16,
|
|
|
+ });
|
|
|
+ console.log('微信地图打开成功');
|
|
|
+ } catch (error) {
|
|
|
+ console.error('微信地图打开失败:', error);
|
|
|
+ this.fallbackOpenMap(latitude, longitude);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ console.log('使用备用地图打开方式...');
|
|
|
this.fallbackOpenMap(latitude, longitude);
|
|
|
}
|
|
|
- } else {
|
|
|
- this.fallbackOpenMap(latitude, longitude);
|
|
|
+ console.log('=== finally块执行完成 ===');
|
|
|
}
|
|
|
},
|
|
|
|