diff --git a/app/web/static/geolocate.js b/app/web/static/geolocate.js index ebaad06..6a24bce 100644 --- a/app/web/static/geolocate.js +++ b/app/web/static/geolocate.js @@ -27,6 +27,26 @@ document.addEventListener('DOMContentLoaded', function() { } } + function formatAddress(item) { + if (!item.address) return item.display_name; + const addr = item.address; + let street = addr.road || addr.pedestrian || addr.cycleway || addr.footway || addr.street || ''; + let number = addr.house_number || ''; + let postcode = addr.postcode || ''; + let city = addr.city || addr.town || addr.village || addr.hamlet || addr.municipality || addr.county || ''; + // Build formatted string: Street Number, Postal code City + let address = ''; + if (street) address += street; + if (number) address += (address ? ' ' : '') + number; + if (postcode || city) { + address += (address ? ', ' : ''); + address += postcode; + if (postcode && city) address += ' '; + address += city; + } + return address; + } + function showSuggestions(inputId, suggestionsId, value) { var suggestionsBox = document.getElementById(suggestionsId); if (!value) { @@ -34,7 +54,7 @@ document.addEventListener('DOMContentLoaded', function() { suggestionsBox.style.display = 'none'; return; } - fetch('https://nominatim.openstreetmap.org/search?format=json&q=' + encodeURIComponent(value)) + fetch('https://nominatim.openstreetmap.org/search?format=json&addressdetails=1&q=' + encodeURIComponent(value)) .then(response => response.json()) .then(data => { suggestionsBox.innerHTML = ''; @@ -43,10 +63,11 @@ document.addEventListener('DOMContentLoaded', function() { var option = document.createElement('button'); option.type = 'button'; option.className = 'list-group-item list-group-item-action'; - option.textContent = item.display_name; + option.textContent = formatAddress(item); + option.title = item.display_name; // Show full address on hover option.onclick = function() { var input = document.getElementById(inputId); - input.value = item.display_name; + input.value = formatAddress(item); input.dataset.lat = item.lat; input.dataset.lon = item.lon; suggestionsBox.innerHTML = ''; diff --git a/app/web/static/index.html b/app/web/static/index.html index a0210a9..17a1c0a 100644 --- a/app/web/static/index.html +++ b/app/web/static/index.html @@ -1,10 +1,9 @@ - + - FreeMoto Web + FreeMoto Navigation -
-
-

FreeMoto Route Planner

-
+