From 378f71f3c75996999af11bc91ff36eb1443b846d Mon Sep 17 00:00:00 2001 From: Apcallover <1503963513@qq.com> Date: Mon, 24 Nov 2025 18:40:59 +0800 Subject: [PATCH] =?UTF-8?q?flat:=20=E5=AF=B9=E6=8E=A5=E7=BB=8F=E7=BA=AC?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stores/useLocationStore.js | 66 ++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 39 deletions(-) diff --git a/stores/useLocationStore.js b/stores/useLocationStore.js index e4d2d05..bb7ecbf 100644 --- a/stores/useLocationStore.js +++ b/stores/useLocationStore.js @@ -16,46 +16,34 @@ const useLocationStore = defineStore("location", () => { function getLocation() { return new Promise((resole, reject) => { - uni.getLocation({ - type: 'wgs84', - altitude: true, - isHighAccuracy: true, - enableHighAccuracy: true, // 关键参数:启用传感器辅助 - timeout: 10000, - success: function(res) { - const resd = { - longitude: 120.382665, - latitude: 36.066938 + try { + lightAppJssdk.map.getLocation({ + success: function(data) { + longitudeVal.value = Number(data.longitude) + latitudeVal.value = Number(data.latitude) + resole(data) + }, + fail: function(data) { + longitudeVal.value = 120.382665 + latitudeVal.value = 36.066938 + resole({ + longitude: 120.382665, + latitude: 36.066938 + }) + msg('用户位置获取失败') + console.log('失败', data) } - if (config.UsingSimulatedPositioning) { // 使用模拟定位 - longitudeVal.value = resd.longitude - latitudeVal.value = resd.latitude - msg('用户位置获取成功') - resole(resd) - } else { - longitudeVal.value = res.longitude - latitudeVal.value = res.latitude - msg('用户位置获取成功') - resole(res) - } - }, - fail: function(err) { - // longitudeVal.value = '' - // latitudeVal.value = '' - // reject(err) - const resd = { - longitude: 120.382665, - latitude: 36.066938 - } - longitudeVal.value = resd.longitude - latitudeVal.value = resd.latitude - msg('用户位置获取失败,使用模拟定位') - resole(resd) - }, - complete: function(e) { - console.warn('getUserLocation' + JSON.stringify(e)) - } - }) + }) + } catch (e) { + longitudeVal.value = 120.382665 + latitudeVal.value = 36.066938 + resole({ + longitude: 120.382665, + latitude: 36.066938 + }) + msg('测试环境,使用模拟定位') + console.log('失败', data) + } }) }