58 lines
1.4 KiB
PHP
58 lines
1.4 KiB
PHP
<?php
|
|
|
|
include_once("config.php");
|
|
|
|
if (!$location) {
|
|
die("Location 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 WHERE device='" . mysqli_real_escape_string($conn, $_GET["device"]) . "' ORDER BY ts DESC LIMIT 1;";
|
|
$result = $conn->query($sql);
|
|
|
|
if ($result->num_rows != 0) {
|
|
|
|
while($row = $result->fetch_assoc()) {
|
|
print '<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset=utf-8>
|
|
<title>Current Location</title>
|
|
|
|
<link rel="stylesheet" href="https://npmcdn.com/leaflet@1.0.0-rc.3/dist/leaflet.css" />
|
|
<script src="https://npmcdn.com/leaflet@1.0.0-rc.3/dist/leaflet.js"></script>
|
|
|
|
' . $headercode . '
|
|
|
|
</head>
|
|
<body>
|
|
|
|
<h1>My location at ' . $row["ts"] . '</h1>
|
|
<p>(last known position where I had a GPS signal, a network connection, and some battery power)</p>
|
|
|
|
<div id="map" style="height:500px;"></div>
|
|
|
|
<script>
|
|
var mymap = L.map("map").setView([' . $row["lat"] . ", " . $row["lon"] . '], 12);
|
|
L.tileLayer("https://b.tile.openstreetmap.org/{z}/{x}/{y}.png").addTo(mymap);
|
|
var marker = L.marker([' . $row["lat"] . ", " . $row["lon"] . ']).addTo(mymap);
|
|
</script>
|
|
|
|
<p>All times in UTC' . date('P') . '.</p>
|
|
|
|
</body>
|
|
</html>';
|
|
}
|
|
} else {
|
|
die("No records found.");
|
|
}
|
|
|
|
$conn->close();
|
|
|
|
?>
|
|
|