Add location.php to get last known location

This commit is contained in:
Klaus-Uwe Mitterer 2016-08-15 00:54:09 +02:00
parent 97b04eff7b
commit 47fbac7f16
1 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,53 @@
<?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>
</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:200px;"></div>
<script>
var mymap = L.map("map").setView([0.0, 0.0], 0);
L.tileLayer("https://b.tile.openstreetmap.org/{z}/{x}/{y}.png").addTo(mymap);
var marker = L.marker([' . $row["lat"] . ", " . $row["lon"] . ']).addTo(mymap);
</script>
</body>
</html>';
}
} else {
die("No records found.");
}
$conn->close();
?>