gpstools/access.php
2016-08-07 22:09:56 +02:00

56 lines
1.2 KiB
PHP

<?php
include_once("config.php");
if (!$access) {
die("Access not enabled in configuration file. Make sure that this page is not public before enabling it.");
}
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT ts, lat, lon FROM tracker ORDER BY ts ASC;";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
header('Content-Type: application/vnd.google-earth.kml+xml');
header('Content-Disposition: attachment; filename="export.kml"');
echo '<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Style id="yellowPoly">
<LineStyle>
<color>7f00ffff</color>
<width>4</width>
</LineStyle>
<PolyStyle>
<color>7f00ff00</color>
</PolyStyle>
</Style>
<Placemark><styleUrl>#yellowPoly</styleUrl>
<LineString>
<extrude>1</extrude>
<tesselate>1</tesselate>
<altitudeMode>absolute</altitudeMode>
<coordinates>
';
while($row = $result->fetch_assoc()) {
echo $row["lon"] . "," . $row["lat"] . "\n";
}
echo '</coordinates>
</LineString></Placemark>
</Document></kml>';
} else {
die("No records found.");
}
$conn->close();
?>