From 7d88ad036d51407f60d98784a8a69bcaae0e2438 Mon Sep 17 00:00:00 2001 From: Carsten Graf Date: Mon, 8 Sep 2025 21:41:58 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Fix=20location=20name:=20Use=20r?= =?UTF-8?q?eal=20location=20name=20from=20API=20instead=20of=20search=20te?= =?UTF-8?q?rm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added hidden field 'realLocationName' to store actual location name from Nominatim API - Updated location saving to use real location name (display_name) instead of search term - Fallback to search term if real location name not available - Now saves proper location names like 'Marienplatz, Altstadt-Lehel, München, Bayern, Deutschland' instead of just 'München' - Improved location data quality in database --- public/js/generator.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/public/js/generator.js b/public/js/generator.js index 73326e9..a90212d 100644 --- a/public/js/generator.js +++ b/public/js/generator.js @@ -172,7 +172,7 @@ function toggleTokenFields() { // Standort automatisch speichern, falls vorhanden let locationSaved = false; - const locationName = document.getElementById('locationSearch')?.value?.trim(); + const locationName = document.getElementById('realLocationName')?.value || document.getElementById('locationSearch')?.value?.trim(); const latitude = document.getElementById('latitude')?.textContent; const longitude = document.getElementById('longitude')?.textContent; @@ -331,6 +331,19 @@ function toggleTokenFields() { const lat = parseFloat(location.lat); const lon = parseFloat(location.lon); + // Echten Standortnamen aus der API speichern + const realLocationName = location.display_name || location.name || locationInput; + + // Verstecktes Feld für echten Standortnamen erstellen/aktualisieren + let locationNameField = document.getElementById('realLocationName'); + if (!locationNameField) { + locationNameField = document.createElement('input'); + locationNameField.type = 'hidden'; + locationNameField.id = 'realLocationName'; + document.body.appendChild(locationNameField); + } + locationNameField.value = realLocationName; + // Koordinaten anzeigen updateCoordinates(lat, lon); coordinatesDiv.style.display = 'block'; @@ -340,7 +353,7 @@ function toggleTokenFields() { mapContainer.style.display = 'block'; // Erfolgsmeldung - showSuccess(`✅ Standort "${locationInput}" erfolgreich gefunden! Klicken Sie auf die Karte, um den Pin zu verschieben.`); + showSuccess(`✅ Standort "${realLocationName}" erfolgreich gefunden! Klicken Sie auf die Karte, um den Pin zu verschieben.`); } catch (error) { showError(`Fehler bei der Standortsuche: ${error.message}`); @@ -460,7 +473,7 @@ function toggleTokenFields() { // Standort in Datenbank speichern async function saveLocationToDatabase() { - const locationName = document.getElementById('locationSearch').value.trim(); + const locationName = document.getElementById('realLocationName')?.value || document.getElementById('locationSearch').value.trim(); const latitude = document.getElementById('latitude').textContent; const longitude = document.getElementById('longitude').textContent; const saveBtn = document.getElementById('saveLocationBtn');