michaelyuen

Untitled

Dec 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <form>
  2.     <input type="text" id="lat" name="lat">
  3.     <input type="text" id="lon" name="lon">
  4. </form>
  5.  
  6. <script>
  7.     function show_position(position) {
  8.         document.getElementById('lat').value = position.coords.latitude;
  9.         document.getElementById('lon').value = position.coords.longitude;
  10.     }
  11.  
  12.     function get_geolocation(){
  13.         if (navigator.geolocation) {
  14.             navigator.geolocation.getCurrentPosition(show_position);
  15.         }
  16.     }
  17.  
  18.     document.addEventListener("DOMContentLoaded", function(event) {
  19.         get_geolocation();
  20.     });
  21. </script>
Add Comment
Please, Sign In to add comment