Update templates/index.html
Browse files- templates/index.html +6 -8
templates/index.html
CHANGED
|
@@ -39,7 +39,6 @@
|
|
| 39 |
<div id="map"></div>
|
| 40 |
</div>
|
| 41 |
<div class="col-lg-4">
|
| 42 |
-
<!-- NEW: Location Search Bar -->
|
| 43 |
<div class="input-group mb-3">
|
| 44 |
<input type="text" id="location-search" class="form-control" placeholder="Search location (e.g., Paris, France)">
|
| 45 |
<button class="btn btn-outline-secondary" type="button" id="search-button">
|
|
@@ -47,7 +46,6 @@
|
|
| 47 |
</button>
|
| 48 |
</div>
|
| 49 |
<hr>
|
| 50 |
-
<!-- End of New Section -->
|
| 51 |
<div class="mb-3">
|
| 52 |
<label for="lat" class="form-label">Latitude</label>
|
| 53 |
<input type="text" id="lat" class="form-control" placeholder="Click map or enter manually">
|
|
@@ -140,7 +138,6 @@
|
|
| 140 |
});
|
| 141 |
};
|
| 142 |
|
| 143 |
-
// --- NEW: Location Search Functionality ---
|
| 144 |
document.getElementById('search-button').addEventListener('click', () => {
|
| 145 |
const query = document.getElementById('location-search').value;
|
| 146 |
if (!query) {
|
|
@@ -150,10 +147,9 @@
|
|
| 150 |
|
| 151 |
const searchButton = document.getElementById('search-button');
|
| 152 |
const searchIcon = searchButton.querySelector('i');
|
| 153 |
-
// Show loading state
|
| 154 |
searchButton.disabled = true;
|
| 155 |
searchIcon.style.display = 'none';
|
| 156 |
-
searchButton.innerHTML = `<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>`
|
| 157 |
|
| 158 |
const apiUrl = `https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(query)}`;
|
| 159 |
|
|
@@ -164,7 +160,10 @@
|
|
| 164 |
})
|
| 165 |
.then(data => {
|
| 166 |
if (data && data.length > 0) {
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
| 168 |
const lat = parseFloat(result.lat).toFixed(6);
|
| 169 |
const lon = parseFloat(result.lon).toFixed(6);
|
| 170 |
|
|
@@ -182,10 +181,9 @@
|
|
| 182 |
})
|
| 183 |
.catch(error => showAlert(`Failed to search for location: ${error.message}`))
|
| 184 |
.finally(() => {
|
| 185 |
-
// Restore button state
|
| 186 |
searchButton.disabled = false;
|
| 187 |
searchButton.querySelector('.spinner-border').remove();
|
| 188 |
-
|
| 189 |
});
|
| 190 |
});
|
| 191 |
|
|
|
|
| 39 |
<div id="map"></div>
|
| 40 |
</div>
|
| 41 |
<div class="col-lg-4">
|
|
|
|
| 42 |
<div class="input-group mb-3">
|
| 43 |
<input type="text" id="location-search" class="form-control" placeholder="Search location (e.g., Paris, France)">
|
| 44 |
<button class="btn btn-outline-secondary" type="button" id="search-button">
|
|
|
|
| 46 |
</button>
|
| 47 |
</div>
|
| 48 |
<hr>
|
|
|
|
| 49 |
<div class="mb-3">
|
| 50 |
<label for="lat" class="form-label">Latitude</label>
|
| 51 |
<input type="text" id="lat" class="form-control" placeholder="Click map or enter manually">
|
|
|
|
| 138 |
});
|
| 139 |
};
|
| 140 |
|
|
|
|
| 141 |
document.getElementById('search-button').addEventListener('click', () => {
|
| 142 |
const query = document.getElementById('location-search').value;
|
| 143 |
if (!query) {
|
|
|
|
| 147 |
|
| 148 |
const searchButton = document.getElementById('search-button');
|
| 149 |
const searchIcon = searchButton.querySelector('i');
|
|
|
|
| 150 |
searchButton.disabled = true;
|
| 151 |
searchIcon.style.display = 'none';
|
| 152 |
+
searchButton.innerHTML = `<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>`;
|
| 153 |
|
| 154 |
const apiUrl = `https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(query)}`;
|
| 155 |
|
|
|
|
| 160 |
})
|
| 161 |
.then(data => {
|
| 162 |
if (data && data.length > 0) {
|
| 163 |
+
// --- THIS IS THE FIX ---
|
| 164 |
+
// Select the first result object from the data array
|
| 165 |
+
const result = data[0];
|
| 166 |
+
|
| 167 |
const lat = parseFloat(result.lat).toFixed(6);
|
| 168 |
const lon = parseFloat(result.lon).toFixed(6);
|
| 169 |
|
|
|
|
| 181 |
})
|
| 182 |
.catch(error => showAlert(`Failed to search for location: ${error.message}`))
|
| 183 |
.finally(() => {
|
|
|
|
| 184 |
searchButton.disabled = false;
|
| 185 |
searchButton.querySelector('.spinner-border').remove();
|
| 186 |
+
searchButton.innerHTML = `<i class="bi bi-search"></i>`;
|
| 187 |
});
|
| 188 |
});
|
| 189 |
|