50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Live Location</title>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<!-- Leaflet CSS -->
|
|
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
|
|
|
|
<!-- Leaflet JS -->
|
|
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
|
|
|
<style>
|
|
#map {
|
|
height: 90vh;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h3>Live Location</h3>
|
|
<div id="map"></div>
|
|
|
|
<script>
|
|
const kurirId = {{ $kurirId }}; // Inject dari server
|
|
|
|
const map = L.map('map').setView([-7.257472, 112.752088], 14);
|
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
attribution: '© OpenStreetMap contributors'
|
|
}).addTo(map);
|
|
|
|
const marker = L.marker([-7.257472, 112.752088]).addTo(map);
|
|
|
|
async function updateLocation() {
|
|
const res = await fetch(`/api/lokasi-kurir/${kurirId}`);
|
|
const data = await res.json();
|
|
|
|
if (data.lat && data.lng) {
|
|
marker.setLatLng([data.lat, data.lng]);
|
|
map.panTo([data.lat, data.lng]);
|
|
}
|
|
}
|
|
|
|
updateLocation(); // Panggil pertama kali
|
|
setInterval(updateLocation, 5000); // Update setiap 5 detik
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|