From 8276edcb6fceded09ad6102dd56cc72b996fa70d Mon Sep 17 00:00:00 2001 From: weipengfei <2187978347@qq.com> Date: Thu, 21 Sep 2023 16:17:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=8E=B7=E5=8F=96=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE,=E5=85=BC=E5=AE=B9=E9=9D=9E=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- subpkg/property/vehicle.vue | 91 ++++++++++++------------------------- 1 file changed, 30 insertions(+), 61 deletions(-) diff --git a/subpkg/property/vehicle.vue b/subpkg/property/vehicle.vue index 8e38a69..13d65c3 100644 --- a/subpkg/property/vehicle.vue +++ b/subpkg/property/vehicle.vue @@ -168,74 +168,43 @@ uni.showLoading({ title: '获取位置中' }) - uni.sendHostEvent('getLocation', '获取位置', (ret) => { - uni.$on('uniMP_getLocation', (res) => { - try { - if(!res.latitude)new Error(); + if (uni.getStorageSync('uniMP')) { + uni.sendHostEvent('getLocation', '获取位置', (ret) => { + uni.$on('uniMP_getLocation', (res) => { + try { + if (!res.latitude) new Error(); + that.markers[1].latitude = res.latitude; + that.markers[1].longitude = res.longitude; + that.getDriverLine(); + uni.hideLoading(); + } catch (e) { + uni.hideLoading(); + Toast('获取位置失败'); + console.log(e); + } + }) + }); + } else { + uni.getLocation({ + // type: 'gcj02', + // geocode: true, + isHighAccuracy: true, + highAccuracyExpireTime: 5 * 1000, + accuracy: 'best', + success: (res) => { that.markers[1].latitude = res.latitude; that.markers[1].longitude = res.longitude; that.getDriverLine(); uni.hideLoading(); - } catch (e) { + console.log(res); + }, + fail(e) { uni.hideLoading(); Toast('获取位置失败'); + console.log(e); } - }) - }); - return ; - uni.getLocation({ - type: 'gcj02', - geocode: true, - isHighAccuracy: true, - success: function async (res) { - that.markers[1].latitude = res.latitude; - that.markers[1].longitude = res.longitude; - that.getDriverLine(); - // uni.hideLoading(); - console.log(res); - uni.showModal({ - title: '成功', - content: JSON.stringify(res) - }) - }, - fail(e) { - // uni.hideLoading(); - Toast('获取位置失败'); - console.log(e); - uni.showModal({ - title: '失败', - content: JSON.stringify(e) - }) - try { - plus.geolocation.getCurrentPosition(function(position) { - console.log('经度:' + position.coords.longitude); - console.log('纬度:' + position.coords.latitude); - that.markers[1].latitude = position.coords.longitude; - that.markers[1].longitude = position.coords.longitude; - that.getDriverLine(); - uni.hideLoading(); - uni.showModal({ - title: 'plus成功', - content: JSON.parse(position) - }) - }, function(error) { - console.error('获取位置失败:', error.message); - uni.showModal({ - title: 'plus失败', - content: JSON.parse(error) - }) - - }); - } catch (e) { - uni.showModal({ - title: '没有plus', - content: JSON.parse(e) - }) - } - } - }); - - + }); + } }, showToast() { this.$refs.uToast.show({