gpstools/location.php

62 lines
1.5 KiB
PHP
Raw Normal View History

<?php
2017-10-05 12:43:11 +00:00
$status = 1;
include_once("config.php");
2017-10-05 12:43:11 +00:00
if (!$location)
die("Location access not enabled in configuration file. Make sure that this page is not public before enabling it.");
2017-10-05 12:43:11 +00:00
if ($locationverification)
include("auth.php");
$conn = new mysqli($servername, $username, $password, $dbname);
2017-10-05 12:43:11 +00:00
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();
?>