-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuser.html
More file actions
82 lines (73 loc) · 2.88 KB
/
user.html
File metadata and controls
82 lines (73 loc) · 2.88 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html>
<head>
<title>User - Bus Tracker (Improved)</title>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<style>
body { margin: 0; font-family: Arial, sans-serif; }
#map { width: 100%; height: 90vh; }
#info { padding: 8px; background: #f5f5f5; font-size: 14px; }
.bad { color: #b00; font-weight: bold; }
.ok { color: #097; font-weight: bold; }
</style>
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css"/>
</head>
<body>
<h3 style="margin:8px">User — Track Driver</h3>
<div id="map"></div>
<div id="info">
Status: <span id="status">Waiting for driver...</span><br/>
Accuracy: <span id="accuracy">—</span><br/>
Last update: <span id="last">—</span>
</div>
<script>
const serverUrl = "INSERT URL HERE";
const statusEl = document.getElementById('status');
const accEl = document.getElementById('accuracy');
const lastEl = document.getElementById('last');
// init map
const map = L.map('map').setView([28.6139, 77.2090], 13); // default Delhi
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
let driverMarker = null;
function updateDriver() {
fetch(serverUrl + "/location")
.then(res => res.json())
.then(data => {
if (!data.lat || !data.lng) {
statusEl.innerHTML = '<span class="bad">Driver has not shared location yet.</span>';
return;
}
const lat = data.lat;
const lng = data.lng;
if (!driverMarker) {
driverMarker = L.marker([lat, lng]).addTo(map).bindPopup("Driver");
map.setView([lat, lng], 15);
} else {
driverMarker.setLatLng([lat, lng]);
}
statusEl.innerHTML = '<span class="ok">Driver location received.</span>';
accEl.textContent = data.accuracy ? data.accuracy + " m" : "unknown";
lastEl.textContent = data.timestamp ? new Date(data.timestamp).toLocaleTimeString() : "unknown";
// hint based on accuracy
if (data.accuracy) {
if (data.accuracy > 200) {
accEl.innerHTML = data.accuracy + ' m <span class="bad">(Low accuracy — coarse/IP-based)</span>';
} else if (data.accuracy > 50) {
accEl.innerHTML = data.accuracy + ' m <span class="ok">(Moderate)</span>';
} else {
accEl.innerHTML = data.accuracy + ' m <span class="ok">(Precise GPS)</span>';
}
}
})
.catch(err => {
console.error("Fetch error", err);
statusEl.innerHTML = '<span class="bad">Error fetching location.</span>';
});
}
setInterval(updateDriver, 3000); // refresh every 3s
</script>
</body>
</html>