Morgen Zusammen,
ich habe mir ein KI-Skript „gezaubert“ das aus 2 Variablen (Breitengrad und Längengrad mit Archiv) einen Streckenverlauf darstellen soll.
Und das macht es eben nicht. Falls hier Jemand Ahnung hat was nicht passen könnte wäre ich dankbar.
Ich denke auch, das es hier auch Bedarf von anderen Usern geben könnte:
<?php
// --- KONFIGURATION ---
$googleApiKey = "xxxx hier dein API Key xxxx";
$htmlBoxID = 12258; // ID der String-Variable mit Profil ~HTMLBox
$latVarID = 47934; // ID der Float-Variable für Breitengrad (Latitude)
$lngVarID = 51204; // ID der Float-Variable für Längengrad (Longitude)
$storageVarID = 42053; // ID einer String-Variable zum dauerhaften Speichern der Liste
// --- DATENVERARBEITUNG ---
$currentLat = GetValueFloat($latVarID);
$currentLng = GetValueFloat($lngVarID);
$routePoints = json_decode(GetValueString($storageVarID), true) ?? [];
$newPoint = ["lat" => $currentLat, "lng" => $currentLng];
if (empty($routePoints) || end($routePoints) !== $newPoint) {
$routePoints[] = $newPoint;
if (count($routePoints) > 300) array_shift($routePoints);
SetValueString($storageVarID, json_encode($routePoints));
}
// --- DATEIPFADE KORRIGIEREN ---
// Wir nutzen den 'user' Ordner im Webfront, da dieser für eigene HTML-Dateien vorgesehen ist
$userDir = IPS_GetKernelDir() . "webfront" . DIRECTORY_SEPARATOR . "user" . DIRECTORY_SEPARATOR;
if (!is_dir($userDir)) mkdir($userDir, 0777, true);
$filename = $userDir . "google_map_route.html";
$jsonPoints = json_encode($routePoints);
// --- HTML INHALT ---
$htmlContent = <<<HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>html, body, #map { height: 100%; margin: 0; padding: 0; }</style>
</head>
<body>
<div id="map"></div>
<script>
function initMap() {
const pathData = $jsonPoints;
if (pathData.length === 0) return;
const map = new google.maps.Map(document.getElementById("map"), {
zoom: 12, center: pathData[pathData.length - 1]
});
new google.maps.Polyline({
path: pathData, geodesic: true, strokeColor: "#FF0000", strokeWeight: 3, map: map
});
const bounds = new google.maps.LatLngBounds();
pathData.forEach(p => bounds.extend(p));
map.fitBounds(bounds);
}
</script>
<script async defer src="maps.googleapis.com"></script>
</body>
</html>
HTML;
// Datei schreiben
file_put_contents($filename, $htmlContent);
// --- AUSGABE IN HTMLBOX ---
// WICHTIG: Der Pfad im Browser muss nun mit /user/ beginnen
$iframeCode = '<iframe src="/user/google_map_route.html?t=' . time() . '" style="width:100%; height:500px; border:none;"></iframe>';
SetValueString($htmlBoxID, $iframeCode);