get your location and save in Mysql

https://forums.digitalpoint.com/threads/how-to-get-longitude-and-latitude-to-my-page-using-html5.1965305/



  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4. <script type="text/javascript">
  5. function initGeolocation()
  6. {
  7.      if( navigator.geolocation )
  8.      {
  9.           // Call getCurrentPosition with success and failure callbacks
  10.           navigator.geolocation.getCurrentPosition( success, fail );
  11.      }
  12.      else
  13.      {
  14.           alert("Sorry, your browser does not support geolocation services.");
  15.      }
  16. }
  17.  
  18. function success(position)
  19. {
  20.  
  21. document.getElementById('long').value = position.coords.longitude;
  22. document.getElementById('lat').value = position.coords.latitude
  23. }
  24. function fail()
  25. {
  26.      // Could not obtain location
  27. }
  28.  
  29. </script>    
  30.   </head>
  31.  
  32. <body onLoad="initGeolocation();">
  33. <FORM NAME="rd" METHOD="POST" ACTION="index.html">
  34. <INPUT TYPE="text" NAME="long" ID="long" VALUE="">
  35. <INPUT TYPE="text" NAME="lat" ID="lat" VALUE="">
  36.   </body>
  37. </html>

No comments:

Post a Comment