fix: robust coordinate parsing and allow score for any valid lat/lon
This commit is contained in:
parent
9ecc4253ee
commit
198bbd89ab
3 changed files with 25 additions and 8 deletions
|
|
@ -516,7 +516,8 @@ def handle_score(handler: BaseHTTPRequestHandler, query: dict[str, list[str]]) -
|
|||
json_response(handler, HTTPStatus.BAD_REQUEST, {"error": "invalid_query"})
|
||||
return
|
||||
|
||||
if not (47.0 <= lat <= 55.5 and 5.0 <= lon <= 16.0):
|
||||
# Accept any valid geographic coordinate so every point can get a score.
|
||||
if not (-90.0 <= lat <= 90.0 and -180.0 <= lon <= 180.0):
|
||||
json_response(handler, HTTPStatus.BAD_REQUEST, {"error": "lat_lon_out_of_bounds"})
|
||||
return
|
||||
|
||||
|
|
|
|||
26
src/app.js
26
src/app.js
|
|
@ -268,8 +268,8 @@ function setCoordinates(lat, lon, options = {}) {
|
|||
}
|
||||
|
||||
function updateMapFromInputs(zoom = null) {
|
||||
const lat = Number(latEl.value);
|
||||
const lon = Number(lonEl.value);
|
||||
const lat = parseCoordinateInput(latEl.value);
|
||||
const lon = parseCoordinateInput(lonEl.value);
|
||||
if (!Number.isFinite(lat) || !Number.isFinite(lon)) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -614,12 +614,15 @@ function findCachedScore(lat, lon) {
|
|||
}
|
||||
|
||||
async function loadScore() {
|
||||
const lat = Number(latEl.value);
|
||||
const lon = Number(lonEl.value);
|
||||
const lat = parseCoordinateInput(latEl.value);
|
||||
const lon = parseCoordinateInput(lonEl.value);
|
||||
if (!Number.isFinite(lat) || !Number.isFinite(lon)) {
|
||||
alert("Bitte gültige Koordinaten eingeben.");
|
||||
alert("Bitte gültige Koordinaten eingeben (z. B. 51.10893 oder 51,10893).");
|
||||
return;
|
||||
}
|
||||
// Normalize input display to avoid locale-related parsing issues on repeated requests.
|
||||
latEl.value = lat.toFixed(6);
|
||||
lonEl.value = lon.toFixed(6);
|
||||
|
||||
loadScoreEl.disabled = true;
|
||||
const at = new Date().toISOString();
|
||||
|
|
@ -627,6 +630,8 @@ async function loadScore() {
|
|||
try {
|
||||
const response = await fetch(`${API_BASE}/spot/score?lat=${encodeURIComponent(lat)}&lon=${encodeURIComponent(lon)}&at=${encodeURIComponent(at)}`);
|
||||
if (!response.ok) {
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
signalStatusEl.textContent = `Live-Score fehlgeschlagen: ${payload.error || `HTTP ${response.status}`}.`;
|
||||
throw new Error("api_error");
|
||||
}
|
||||
|
||||
|
|
@ -652,6 +657,17 @@ async function loadScore() {
|
|||
}
|
||||
}
|
||||
|
||||
function parseCoordinateInput(value) {
|
||||
if (typeof value !== "string") {
|
||||
return Number.NaN;
|
||||
}
|
||||
const normalized = value.trim().replace(",", ".");
|
||||
if (!normalized) {
|
||||
return Number.NaN;
|
||||
}
|
||||
return Number(normalized);
|
||||
}
|
||||
|
||||
function renderScore(data, fromCache, cacheTime = "") {
|
||||
scoreEl.textContent = String(data.score);
|
||||
|
||||
|
|
|
|||
|
|
@ -33,11 +33,11 @@
|
|||
<div class="field-grid">
|
||||
<label>
|
||||
Latitude
|
||||
<input id="lat" type="number" step="0.000001" placeholder="51.2500" />
|
||||
<input id="lat" type="number" step="0.000001" inputmode="decimal" placeholder="51.2500" />
|
||||
</label>
|
||||
<label>
|
||||
Longitude
|
||||
<input id="lon" type="number" step="0.000001" placeholder="6.9700" />
|
||||
<input id="lon" type="number" step="0.000001" inputmode="decimal" placeholder="6.9700" />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue