diff --git a/frontend/src/pages/TourDetailPage.tsx b/frontend/src/pages/TourDetailPage.tsx index 91b8136..7a16fda 100644 --- a/frontend/src/pages/TourDetailPage.tsx +++ b/frontend/src/pages/TourDetailPage.tsx @@ -350,6 +350,21 @@ export const TourDetailPage = ({ const [isAddMemberOpen, setIsAddMemberOpen] = useState(false); const [isAddPhotoOpen, setIsAddPhotoOpen] = useState(false); + // State cho vị trí và hướng của người dùng + + + + const [deviceOrientationHeading, setDeviceOrientationHeading] = useState(null); // Hướng thiết bị (la bàn) + + // Xác định hướng hiển thị của người dùng (ưu tiên hướng di chuyển từ GPS, sau đó đến la bàn thiết bị) + const currentHeading = useMemo(() => { + if (gpsHeading !== null && userSpeed !== null && userSpeed > 0.5) { + return gpsHeading; + } else if (deviceOrientationHeading !== null) { + return deviceOrientationHeading; + } + return 0; + }, [gpsHeading, userSpeed, deviceOrientationHeading]); // Định nghĩa Icons bên trong Component bằng useMemo để đảm bảo tính ổn định và tránh lỗi render const mapIcons = useMemo(() => ({ @@ -374,15 +389,23 @@ export const TourDetailPage = ({ user: L.divIcon({ className: '!bg-transparent !border-none', html: ` -
-
-
+
+ +
+ + +
+ +
+ +
+
`, - iconSize: [16, 16], - iconAnchor: [8, 8] + iconSize: [32, 32], + iconAnchor: [16, 16] }) - }), []); + }), [currentHeading]); useEffect(() => { // Theo dõi vị trí GPS của người dùng (bao gồm hướng và tốc độ khi di chuyển) @@ -404,7 +427,7 @@ export const TourDetailPage = ({ }, [isPublicView]); // Chỉ phụ thuộc vào isPublicView // State mới cho hướng thiết bị (la bàn) - const [deviceOrientationHeading, setDeviceOrientationHeading] = useState(null); + // Theo dõi hướng thiết bị (la bàn) useEffect(() => {