This commit is contained in:
@@ -116,6 +116,7 @@ if ($pdo && ($q !== '' || $loc !== '' || ($lat !== null && $lng !== null))) {
|
||||
</main>
|
||||
<script>
|
||||
(function(){
|
||||
const body = document.body;
|
||||
const locInput = document.getElementById('loc');
|
||||
const latInput = document.getElementById('lat');
|
||||
const lngInput = document.getElementById('lng');
|
||||
@@ -125,8 +126,64 @@ if ($pdo && ($q !== '' || $loc !== '' || ($lat !== null && $lng !== null))) {
|
||||
const btnMap = document.getElementById('btnMap');
|
||||
const mapWrapper = document.getElementById('mapWrapper');
|
||||
const mapContainer = document.getElementById('mapContainer');
|
||||
const isLoggedIn = body?.dataset.auth === '1';
|
||||
const profileLocationPreference = body?.dataset.locationPreference || 'prompt';
|
||||
const locationStorageKey = 'pkt_user_location';
|
||||
const locationSessionStorageKey = 'pkt_user_location_session';
|
||||
let map, marker;
|
||||
|
||||
function effectiveLocationPreference() {
|
||||
if (!isLoggedIn) {
|
||||
try {
|
||||
const guestPreference = window.localStorage.getItem('pkt_location_preference_guest');
|
||||
if (guestPreference && ['disabled', 'prompt', 'enabled'].includes(guestPreference)) {
|
||||
return guestPreference;
|
||||
}
|
||||
} catch (err) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return profileLocationPreference;
|
||||
}
|
||||
|
||||
function getStoredLocation() {
|
||||
const candidates = [];
|
||||
try {
|
||||
const sessionValue = window.sessionStorage.getItem(locationSessionStorageKey);
|
||||
if (sessionValue) candidates.push(sessionValue);
|
||||
} catch (err) {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
const localValue = window.localStorage.getItem(locationStorageKey);
|
||||
if (localValue) candidates.push(localValue);
|
||||
} catch (err) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
for (const value of candidates) {
|
||||
try {
|
||||
const parsed = JSON.parse(value);
|
||||
if (parsed && Number.isFinite(parsed.lat) && Number.isFinite(parsed.lng)) {
|
||||
return parsed;
|
||||
}
|
||||
} catch (err) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function applyLocation(lat, lng, label = 'Mein Standort') {
|
||||
latInput.value = Number(lat).toFixed(6);
|
||||
lngInput.value = Number(lng).toFixed(6);
|
||||
if (locInput && !locInput.value.trim()) {
|
||||
locInput.value = label;
|
||||
}
|
||||
toggleRadius(true);
|
||||
}
|
||||
|
||||
function toggleRadius(show) {
|
||||
if (!radiusWrap) return;
|
||||
radiusWrap.hidden = !show;
|
||||
@@ -198,17 +255,25 @@ if ($pdo && ($q !== '' || $loc !== '' || ($lat !== null && $lng !== null))) {
|
||||
window.PKTConsent?.openPreferences?.();
|
||||
return;
|
||||
}
|
||||
|
||||
const preference = effectiveLocationPreference();
|
||||
if (preference === 'disabled') {
|
||||
alert('Die Standortverwendung ist in deinem Profil deaktiviert.');
|
||||
return;
|
||||
}
|
||||
|
||||
const storedLocation = getStoredLocation();
|
||||
if (preference === 'enabled' && storedLocation) {
|
||||
applyLocation(storedLocation.lat, storedLocation.lng, storedLocation.label || 'Mein Standort');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!navigator.geolocation) {
|
||||
alert('Geolocation wird nicht unterstützt.');
|
||||
return;
|
||||
}
|
||||
navigator.geolocation.getCurrentPosition((pos) => {
|
||||
const lat = pos.coords.latitude;
|
||||
const lng = pos.coords.longitude;
|
||||
latInput.value = lat.toFixed(6);
|
||||
lngInput.value = lng.toFixed(6);
|
||||
if (locInput && !locInput.value.trim()) locInput.value = 'Mein Standort';
|
||||
toggleRadius(true);
|
||||
applyLocation(pos.coords.latitude, pos.coords.longitude, 'Mein Standort');
|
||||
}, () => alert('Standort konnte nicht ermittelt werden.'));
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user