地图优化
This commit is contained in:
parent
5f28cfe935
commit
b935891fda
Binary file not shown.
|
Before Width: | Height: | Size: 831 B After Width: | Height: | Size: 760 B |
|
|
@ -711,8 +711,8 @@
|
|||
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;
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue