51 lines
1 KiB
PHP
51 lines
1 KiB
PHP
<?php
|
|
|
|
include_once("config.php");
|
|
$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();
|
|
|
|
?>
|
|
|