Advertisement
contatowellington

Untitled

Oct 28th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <p>Click the button to get your coordinates.</p>
  6.  
  7. <button onclick="getLocation()">Try It</button>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. var x = document.getElementById("demo");
  13.  
  14. function getLocation() {
  15. if (navigator.geolocation) {
  16. navigator.geolocation.watchPosition(showPosition);
  17. } else {
  18. x.innerHTML = "Geolocation is not supported by this browser.";}
  19. }
  20.  
  21. function showPosition(position) {
  22. x.innerHTML="Latitude: " + position.coords.latitude +
  23. "<br>Longitude: " + position.coords.longitude;
  24. }
  25. </script>
  26.  
  27. </body>
  28. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement