Skip to content

Commit 986320e

Browse files
committed
Created useeffect for setting POI latlongs
1 parent c575ad0 commit 986320e

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/components/routes/RoutePage.jsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ function RoutePage() {
1212
const [orientation, setOrientation] = useState(0);
1313
const [rotation, setRotation] = useState(0);
1414
const [angle, setAngle] = useState(0);
15-
const [latitude, setLatitude] = useState(null);
16-
const [longitude, setLongitude] = useState(null);
17-
const [userLatitude, setUserLatitude] = useState(null);
18-
const [userLongitude, setUserLongitude] = useState(null);
15+
const [latitude, setLatitude] = useState(0);
16+
const [longitude, setLongitude] = useState(0);
17+
const [userLatitude, setUserLatitude] = useState(0);
18+
const [userLongitude, setUserLongitude] = useState(0);
1919
let handlerAvailable = true;
2020
let locationHandlerAvailable = true;
2121
const isIOS =
@@ -80,6 +80,16 @@ function RoutePage() {
8080
}
8181
}
8282

83+
useEffect(() => {
84+
if (!isIOS) {
85+
window.addEventListener(
86+
"deviceorientationabsolute",
87+
deviceOrientationHandler,
88+
true
89+
);
90+
}
91+
}, []);
92+
8393
useEffect(() => {
8494
if (pointsOfInterest) {
8595
setLatitude(
@@ -93,15 +103,7 @@ function RoutePage() {
93103
].longitude
94104
);
95105
}
96-
97-
if (!isIOS) {
98-
window.addEventListener(
99-
"deviceorientationabsolute",
100-
deviceOrientationHandler,
101-
true
102-
);
103-
}
104-
}, []);
106+
}, [pointsOfInterest]);
105107

106108
if (selectedRoute === null) return null;
107109
return (

0 commit comments

Comments
 (0)