-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.html
37 lines (36 loc) · 1.16 KB
/
driver.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Driver Location</title>
<script>
// Function to send location to the backend
function sendLocationToServer(lat, lon) {
fetch('http://localhost:3000/update-driver-location', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ latitude: lat, longitude: lon }),
})
.then(response => response.json())
.catch(error => console.error('Error sending location:', error));
}
// Get the driver's current location every 5 seconds
setInterval(() => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
const lat = position.coords.latitude;
const lon = position.coords.longitude;
sendLocationToServer(lat, lon); // Send location to the server
});
}
}, 5000); // 5 seconds interval
</script>
</head>
<body>
<h2>Driver Location Tracking</h2>
<p>Your location is being sent to the server every 5 seconds.</p>
</body>
</html>