Hallo zusammen,
wie würdet ihr folgenden Code nach IPS bringen? Was ist unter 8.x state of the art um so etwas zu lösen?
<?php
// Beispielhafte Daten
$latitude = [
['TimeStamp' => 1750136700, 'Value' => 47.450103066667, 'Duration' => 300],
['TimeStamp' => 1750137000, 'Value' => 47.450500000000, 'Duration' => 300],
['TimeStamp' => 1750137300, 'Value' => 47.451000000000, 'Duration' => 300],
];
$longitude = [
['TimeStamp' => 1750136700, 'Value' => 8.234567, 'Duration' => 300],
['TimeStamp' => 1750137000, 'Value' => 8.235000, 'Duration' => 300],
['TimeStamp' => 1750137300, 'Value' => 8.236000, 'Duration' => 300],
];
// Kombinieren der Koordinaten zu einem gemeinsamen Array
$gpsDaten = [];
for ($i = 0; $i < min(count($latitude), count($longitude)); $i++) {
$gpsDaten[] = [
'lat' => floatval($latitude[$i]['Value']),
'lng' => floatval($longitude[$i]['Value']),
'timestamp' => $latitude[$i]['TimeStamp'] // alternativ: $longitude[$i]['TimeStamp']
];
}
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Routenverlauf (aus zwei Arrays)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<style>
#map {
height: 90vh;
width: 100%;
}
</style>
</head>
<body>
<h2 style="text-align: center;">Fahrzeugroute (aus PHP-Array)</h2>
<div id="map"></div>
<script>
const gpsDaten = <?php echo json_encode($gpsDaten); ?>;
const map = L.map('map').setView([50, 10], 6);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap-Mitwirkende'
}).addTo(map);
const latlngs = gpsDaten.map(p => [p.lat, p.lng]);
if (latlngs.length > 0) {
const route = L.polyline(latlngs, { color: 'blue' }).addTo(map);
L.marker(latlngs[0]).addTo(map).bindPopup("Start").openPopup();
L.marker(latlngs[latlngs.length - 1]).addTo(map).bindPopup("Ziel");
map.fitBounds(route.getBounds());
} else {
alert("Keine GPS-Daten gefunden.");
}
</script>
</body>
</html>