Spaces:
Sleeping
Sleeping
added
Browse files
main.py
CHANGED
|
@@ -21,20 +21,14 @@ html_template = """
|
|
| 21 |
<div id="map">Loading map...</div>
|
| 22 |
|
| 23 |
<script>
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
alert("Geolocation is not supported by this browser.");
|
| 29 |
-
}
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
function showPosition(position) {
|
| 33 |
-
const lat = position.coords.latitude;
|
| 34 |
-
const lng = position.coords.longitude;
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
|
|
|
| 38 |
|
| 39 |
// Basemap layers
|
| 40 |
const googleHybridLayer = L.tileLayer('https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}', {
|
|
@@ -60,10 +54,39 @@ html_template = """
|
|
| 60 |
};
|
| 61 |
L.control.layers(baseLayers).addTo(map);
|
| 62 |
|
| 63 |
-
//
|
| 64 |
-
|
| 65 |
-
.
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
}
|
| 68 |
|
| 69 |
function showError(error) {
|
|
|
|
| 21 |
<div id="map">Loading map...</div>
|
| 22 |
|
| 23 |
<script>
|
| 24 |
+
let map;
|
| 25 |
+
let marker;
|
| 26 |
+
let path = []; // Array to store the trajectory points
|
| 27 |
+
let polyline; // Polyline to show the trajectory
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
function initMap() {
|
| 30 |
+
// Initialize map with default coordinates
|
| 31 |
+
map = L.map('map').setView([23.2136165, 72.6873751], 15);
|
| 32 |
|
| 33 |
// Basemap layers
|
| 34 |
const googleHybridLayer = L.tileLayer('https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}', {
|
|
|
|
| 54 |
};
|
| 55 |
L.control.layers(baseLayers).addTo(map);
|
| 56 |
|
| 57 |
+
// Start watching the user's location
|
| 58 |
+
if (navigator.geolocation) {
|
| 59 |
+
navigator.geolocation.watchPosition(showPosition, showError);
|
| 60 |
+
} else {
|
| 61 |
+
alert("Geolocation is not supported by this browser.");
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
function showPosition(position) {
|
| 66 |
+
const lat = position.coords.latitude;
|
| 67 |
+
const lng = position.coords.longitude;
|
| 68 |
+
|
| 69 |
+
// Update marker position or create a new marker
|
| 70 |
+
if (marker) {
|
| 71 |
+
marker.setLatLng([lat, lng]).update(); // Update existing marker position
|
| 72 |
+
} else {
|
| 73 |
+
marker = L.marker([lat, lng]).addTo(map)
|
| 74 |
+
.bindPopup("<b>Your Location</b>")
|
| 75 |
+
.openPopup(); // Create new marker
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
// Center the map on the user's location
|
| 79 |
+
map.setView([lat, lng], 15);
|
| 80 |
+
|
| 81 |
+
// Store the current position in the path array
|
| 82 |
+
path.push([lat, lng]);
|
| 83 |
+
|
| 84 |
+
// If the polyline doesn't exist, create it
|
| 85 |
+
if (!polyline) {
|
| 86 |
+
polyline = L.polyline(path, { color: 'blue' }).addTo(map);
|
| 87 |
+
} else {
|
| 88 |
+
polyline.setLatLngs(path); // Update polyline with new path
|
| 89 |
+
}
|
| 90 |
}
|
| 91 |
|
| 92 |
function showError(error) {
|