A simple way to track your position.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.3KB

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset=utf-8 />
  5. <title>HRP Geolocator</title>
  6. <style type="text/css">* { border: 0; margin: 0; padding: 0; width: 100%; height: 100%;}</style>
  7. </head>
  8. <?php if( isset($_POST['button']) ) {
  9. if( $_POST['lat'] != 0 && $_POST['lon'] != 0)
  10. file_put_contents("positions.txt", date("d/m/o H:i", time()).",".$_POST['lat'].",".$_POST['lon']."\n", FILE_APPEND); ?>
  11. <body>
  12. <p>Position added.</p>
  13. </body>
  14. <?php }
  15. else { ?>
  16. <body onload="getLocation()">
  17. <form method="post">
  18. <input type="hidden" name="lat" id="lat" value="0">
  19. <input type="hidden" name="lon" id="lon" value="0">
  20. <button type="submit" name="button" id="button">Waiting for geolocation...</button>
  21. </form>
  22. <script>
  23. var x = document.getElementById("button");
  24. function getLocation() {
  25. if (navigator.geolocation) {
  26. navigator.geolocation.getCurrentPosition(showPosition);
  27. } else {
  28. x.innerHTML = "Geolocation is not supported by this browser.";
  29. }
  30. }
  31. function showPosition(position) {
  32. document.getElementById("lat").value = position.coords.latitude;
  33. document.getElementById("lon").value = position.coords.longitude;
  34. x.innerHTML = "Latitude: " + position.coords.latitude +
  35. "<br>Longitude: " + position.coords.longitude;
  36. }
  37. </script>
  38. </body>
  39. <?php } ?>
  40. </html>