Add detailed coordinate debugging and validation

- Log latitude/longitude values and types before parsing
- Add null checks for marker_label and display_time
- Improve history polyline filtering for invalid coords
- Show "Keine aktuelle Position" when no current location

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-14 15:47:26 +00:00
parent 40aecaafc0
commit 2c16642992

View File

@@ -117,10 +117,21 @@
if (data.current) { if (data.current) {
const loc = data.current; const loc = data.current;
console.log('Current location:', loc); console.log('Current location object:', loc);
console.log('latitude field:', loc.latitude, 'type:', typeof loc.latitude);
console.log('longitude field:', loc.longitude, 'type:', typeof loc.longitude);
const lat = parseFloat(loc.latitude);
const lon = parseFloat(loc.longitude);
console.log('Parsed lat:', lat, 'lon:', lon);
if (isNaN(lat) || isNaN(lon)) {
throw new Error(`Invalid coordinates: lat=${loc.latitude} (${typeof loc.latitude}), lon=${loc.longitude} (${typeof loc.longitude})`);
}
// Popup-Inhalt aufbauen // Popup-Inhalt aufbauen
let popupContent = `${loc.marker_label}<br>${loc.display_time}`; let popupContent = `${loc.marker_label || 'Unknown'}<br>${loc.display_time || ''}`;
// Batterie hinzufügen, falls vorhanden // Batterie hinzufügen, falls vorhanden
if (loc.battery !== undefined && loc.battery !== null) { if (loc.battery !== undefined && loc.battery !== null) {
@@ -133,13 +144,6 @@
popupContent += `<br>🚗 Speed: ${speedKmh} km/h`; popupContent += `<br>🚗 Speed: ${speedKmh} km/h`;
} }
const lat = parseFloat(loc.latitude);
const lon = parseFloat(loc.longitude);
if (isNaN(lat) || isNaN(lon)) {
throw new Error(`Invalid coordinates: lat=${loc.latitude}, lon=${loc.longitude}`);
}
const marker = L.marker([lat, lon]) const marker = L.marker([lat, lon])
.addTo(map) .addTo(map)
.bindPopup(popupContent) .bindPopup(popupContent)
@@ -151,12 +155,25 @@
// Historie als Linie // Historie als Linie
if (data.history && data.history.length > 1) { if (data.history && data.history.length > 1) {
const coords = data.history.map(h => [parseFloat(h.latitude), parseFloat(h.longitude)]); const coords = data.history
const polyline = L.polyline(coords, {color: 'blue', weight: 3}).addTo(map); .map(h => {
polylines.push(polyline); const hlat = parseFloat(h.latitude);
const hlon = parseFloat(h.longitude);
if (!isNaN(hlat) && !isNaN(hlon)) {
return [hlat, hlon];
}
return null;
})
.filter(c => c !== null);
if (coords.length > 1) {
const polyline = L.polyline(coords, {color: 'blue', weight: 3}).addTo(map);
polylines.push(polyline);
}
} }
} else { } else {
console.log('No current location in response'); console.log('No current location in response');
statusDiv.innerHTML += '<br>Keine aktuelle Position';
} }
} catch (error) { } catch (error) {
console.error('Load error:', error); console.error('Load error:', error);