Advertisement
metalx1000

GPS Marker Log

Feb 17th, 2015
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE HTML>
  2. <head>
  3.   <meta name="viewport" content="width=device-width, initial-scale=1">
  4.   <script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
  5.   <script type="text/javascript">
  6.     var watchID;
  7.     var geoLoc;
  8.     var latitude;
  9.     var longitude;
  10.  
  11.     function showLocation(position) {
  12.       latitude = position.coords.latitude;
  13.       longitude = position.coords.longitude;
  14.       var output=document.getElementById("output");
  15.       output.innerHTML="Latitude : " + latitude + "<br> Longitude: " + longitude;
  16.     }
  17.  
  18.     function errorHandler(err) {
  19.       if(err.code == 1) {
  20.         alert("Error: Access is denied!");
  21.       }else if( err.code == 2) {
  22.         alert("Error: Position is unavailable!");
  23.       }
  24.     }
  25.     function getLocationUpdate(){
  26.  
  27.        if(navigator.geolocation){
  28.           var options = {enableHighAccuracy:true,maximumAge:30000,timeout:27000};
  29.           geoLoc = navigator.geolocation;
  30.           watchID = geoLoc.watchPosition(showLocation, errorHandler, options);
  31.        }else{
  32.           alert("Sorry, browser does not support geolocation!");
  33.        }
  34.     }
  35.  
  36.     function log(){
  37.       var marker = $("#marker").val();
  38.       $("#output2").append(marker + ": ");
  39.       $("#output2").append(latitude + "," + longitude);
  40.       $("#output2").append("<br>");
  41.  
  42.       localStorage.greenway = $("#output2").html();
  43.      
  44.       var info = marker + "|" + latitude + "|" + longitude;
  45.       $.post( "add.php", { info: info } )
  46.         .done(function( data ) {
  47.           console.log(data);
  48.         });
  49.  
  50.       $("#marker").val(+marker + 1);
  51.     }
  52.  
  53.     $(document).ready(function(){
  54.       getLocationUpdate();
  55.       $("#output2").html(localStorage.greenway);
  56.     });
  57.  
  58.   </script>
  59. <html>
  60. <body>
  61.     <input type="number" id="marker"></input>
  62.     <input type="button" onclick="log();" value="LOG"/>
  63.     <div id="output"></div>
  64.     <hr>
  65.     <div id="output2"></div>
  66. </body>
  67. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement