From b935891fdae0cc810b5ab34401b407f1c501192b Mon Sep 17 00:00:00 2001 From: cwchen <1048842385@qq.com> Date: Thu, 15 Jan 2026 14:43:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=B0=E5=9B=BE=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/static/image/real_postion.png | Bin 831 -> 760 bytes src/static/map.html | 60 +++++++++++++++++------------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/static/image/real_postion.png b/src/static/image/real_postion.png index b8bf71a6e1727ac8b0ae9933c3dffde2a5d8f81a..9c18627de6496bef878e0eecd8e369d703d45bba 100644 GIT binary patch literal 760 zcmV+=00009a7bBm000XU z000XU0RWnu7ytkO0drDELIAGL9O(c600d`2O+f$vv5yPYT7GHwFd?|DiFW*z& zBy)LHTZJYf5l1VF&jD=iK}7qba@V1WbR@F3w*3WSHiycsK@+Kn><6QLh)I5^l;T=b z)#+ORDlnCtnLqr0JA|gWOqP%6F$GY&}tK z*W}P76A^j|k3=w-1fwH_N3i#d=EIHbHip3{Fqa|aeh~DJQi=ueu9UaNyykNOn*~4n z?rA|l!}RDX--^FZ50Ias3+DqafV>^q`8+9xJo$MQTB#OBj90id$=Tb6h!LhLEZ2!T!Wh&Y*)#HDDK8T^v0008?NklxvSq*_nZc&O4IT`#K{6N^ z?7{N>>~6EkCGDmO;%2&&mwo$oU-rwtujwAnLEAxgbx8k3Nu^XMHWV9l0ooa)0FA{G zF(qJ2v6)ylme^8kCKgJp@zomg#!Nj+Qbn*>cCS;8aKqET_$Z)bS=Z>=9&)M%58kOC zpN4oeIM92hKY{oI5WNC|W1#mO7`+ANpOLlwJzNnd7EmfJuHV%hGFBm`DiN^c#VuU6 z+YpXW6Mq&L2|4jd1}~VKBa#Kby)CE{~k`2pGKv>W z?;n;Q3CH8Kai6{f z8cKZ*Hsw`A>Z460Ie|imQVTEXz{@YXZ+hp;IXQ=pU+EShHJm-#$~PQduY69UAl0Oq zq{@BFT-FsK_d)dvN1Ls3ZU-0hK}nH(!oy2{trmqVuf{1to+3hk6l>ah^LgQt&;jPS zi8;B8O?gGgI7mTIAg+UT6u_bRh+~Tun!1+MwW7#8ija&D^hq#T!7}DpD*q~WXn*B) z?Aw>>+Buu*C!B?}>n!Xa^blYUr`cL0B+Z%fa_?U&ENgh&g`^d+hD{lDKgj&B zGv;gjr*d8_4gx8$4axONmJQ(A8wVbgKp^(& zDEB!J-KbzsR3xa5Y`AX+X&(BxADrB|8bnV|(3emKD}AOc)uZnip(25coS2u}3exUC zShIOgVuavP@{175cqDVYsNU*DB<_860%>;>l2nYxIhUSr6X^+Sm(=xZ 2 || + // 位置变化超过0.3米就更新(极高灵敏度),或者精度提升超过5米 + if (distance > 0.3 || (accuracy < this.state.currentLocation.accuracy - 5) || (accuracy < 50 && this.state.currentLocation.accuracy >= 50)) { shouldUpdate = true; @@ -732,8 +732,8 @@ const timeDiff = (now - this.lastLocationTime) / 1000; // 秒 if (timeDiff > 0) { const speed = distance / timeDiff; // 米/秒 - // 如果速度超过0.3米/秒(约1公里/小时),认为在移动 - this.isMoving = speed > 0.3; + // 如果速度超过0.05米/秒(极低阈值),认为在移动 + this.isMoving = speed > 0.05; } } @@ -755,14 +755,14 @@ } }, { enableHighAccuracy: true, // 使用GPS精确定位 - timeout: 10000 // 10秒超时 + timeout: 20000 // 20秒超时(给GPS足够时间) }); }; // 先快速获取位置 getQuickPosition(); - // 持续监听位置变化(使用定时器定期获取,实时更新) + // 持续监听位置变化(使用定时器定期获取,改为每5秒更新一次) this.state.watchLocationTimer = setInterval(() => { geolocation.getCurrentPosition((result) => { const status = geolocation.getStatus(); @@ -788,14 +788,23 @@ point.lat ); - // 位置变化超过2米就更新,或者精度提升超过5米 - if (distance > 2 || + // 位置变化超过0.3米就更新(极高灵敏度),或者精度提升超过5米 + if (distance > 0.3 || (accuracy < this.state.currentLocation.accuracy - 5) || (accuracy < 50 && this.state.currentLocation.accuracy >= 50)) { shouldUpdate = true; } } + // 强制每3秒更新一次,即使位置变化不大 + const now = Date.now(); + if (!this.lastForceUpdateTime) this.lastForceUpdateTime = 0; + if ((now - this.lastForceUpdateTime) > 3000) { + shouldUpdate = true; + this.lastForceUpdateTime = now; + console.log('⚠️ 强制位置更新(3秒周期)'); + } + if (shouldUpdate) { const oldLocation = this.state.currentLocation; const distance = oldLocation ? calculateDistance( @@ -803,13 +812,12 @@ ) : 0; // 检测移动状态(通过位置变化速度) - const now = Date.now(); if (this.lastLocationTime > 0 && this.lastLocationPoint) { const timeDiff = (now - this.lastLocationTime) / 1000; // 秒 if (timeDiff > 0) { const speed = distance / timeDiff; // 米/秒 - // 如果速度超过0.3米/秒(约1公里/小时),认为在移动 - this.isMoving = speed > 0.3; + // 如果速度超过0.05米/秒(极低阈值),认为在移动 + this.isMoving = speed > 0.05; } } @@ -834,9 +842,9 @@ } }, { enableHighAccuracy: true, // 使用GPS精确定位 - timeout: 6000 // 6秒超时 + timeout: 15000 // 15秒超时(给GPS足够时间) }); - }, 500); // 每0.5秒更新一次,提高实时性和灵敏度 + }, 5000); // 每5秒更新一次位置 // 保存geolocation实例,以便后续使用 this.baiduGeolocation = geolocation; @@ -894,7 +902,7 @@ } }); - // 持续监听位置变化 + // 持续监听位置变化(改为每5秒更新一次) this.state.watchLocationTimer = setInterval(() => { uni.getLocation({ type: 'wgs84', @@ -920,7 +928,7 @@ console.error('uni-app GPS定位更新失败:', err); } }); - }, 3000); // 每3秒更新一次,给GPS更多时间 + }, 5000); // 每5秒更新一次 }, /** @@ -967,7 +975,7 @@ } }); - // 持续监听位置变化 + // 持续监听位置变化(改为每5秒更新一次) this.state.watchLocationTimer = setInterval(() => { uni.getLocation({ type: 'gcj02', @@ -993,7 +1001,7 @@ console.error('uni-app定位更新失败:', err); } }); - }, 2000); // 每2秒更新一次位置 + }, 5000); // 每5秒更新一次位置 }, /** @@ -1379,10 +1387,10 @@ } else { // 如果不支持setPosition,检查位置是否变化(降低阈值,提高灵敏度) const currentPoint = this.overlays.locationMarker.getPosition(); - // 降低坐标变化阈值,从0.000001(约0.1米)到0.000005(约0.5米),但实际应该总是更新 + // 极低坐标变化阈值0.0000005(约0.05米),实时更新位置 if (!currentPoint || - Math.abs(currentPoint.lng - lng) > 0.000005 || - Math.abs(currentPoint.lat - lat) > 0.000005) { + Math.abs(currentPoint.lng - lng) > 0.0000005 || + Math.abs(currentPoint.lat - lat) > 0.0000005) { // 位置变化,需要更新(但尽量不删除重建) const currentIcon = this.overlays.locationMarker.getIcon(); this.map.removeOverlay(this.overlays.locationMarker); @@ -1392,8 +1400,8 @@ } // 实时更新方向(使用角度差值计算,考虑0-360度边界) - // 移动时提高阈值(2度),减少抖动;静止时降低阈值(1度),保持响应性 - const headingThreshold = this.isMoving ? 2 : 1; + // 移动时1.5度,静止时0.3度,极高灵敏度 + const headingThreshold = this.isMoving ? 1.5 : 0.3; const headingChanged = !this.lastHeading || Math.abs(this.angleDifference(this.state.currentHeading, this.lastHeading)) >= headingThreshold; if (headingChanged) { @@ -1788,8 +1796,8 @@ const oldHeading = this.state.currentHeading; const diff = Math.abs(this.angleDifference(newHeading, oldHeading)); - // 移动时提高阈值(2度),减少抖动;静止时降低阈值(1度),保持响应性 - const threshold = this.isMoving ? 2 : 1; + // 移动时1.5度,静止时0.3度,极高灵敏度 + const threshold = this.isMoving ? 1.5 : 0.3; if (diff >= threshold || oldHeading === 0) { this.state.currentHeading = newHeading; @@ -1840,8 +1848,8 @@ */ handleOrientation(event) { const now = Date.now(); - // 节流:限制更新频率到每50ms一次(20Hz),平衡实时性和性能 - if (now - this.lastOrientationUpdateTime < 50) { + // 节流:限制更新频率到每20ms一次(50Hz),极高响应速度 + if (now - this.lastOrientationUpdateTime < 20) { return; } this.lastOrientationUpdateTime = now;