Advertisement
contatowellington

Untitled

Oct 16th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4. <p id="demo">Clique no botão para receber as coordenadas:</p>
  5. <button onclick="getLocation()">Clique Aqui</button>
  6. <p>
  7. <script>
  8. var x=document.getElementById("demo");
  9. function getLocation()
  10. {
  11. if (navigator.geolocation)
  12. {
  13. navigator.geolocation.getCurrentPosition(showPosition,showError);
  14. }
  15. else{x.innerHTML="Seu browser não suporta Geolocalização.";}
  16. }
  17. function showPosition(position)
  18. {
  19. x.innerHTML="Latitude: " + position.coords.latitude +
  20. "<br>Longitude: " + position.coords.longitude;
  21. }
  22. function showError(error)
  23. {
  24. switch(error.code)
  25. {
  26. case error.PERMISSION_DENIED:
  27. x.innerHTML="Usuário rejeitou a solicitação de Geolocalização."
  28. break;
  29. case error.POSITION_UNAVAILABLE:
  30. x.innerHTML="Localização indisponível."
  31. break;
  32. case error.TIMEOUT:
  33. x.innerHTML="A requisição expirou."
  34. break;
  35. case error.UNKNOWN_ERROR:
  36. x.innerHTML="Algum erro desconhecido aconteceu."
  37. break;
  38. }
  39. }
  40. </script>
  41. </p>
  42. <form name="form1" method="post" action="">
  43. <p>
  44. <label>
  45. <input type="text" name="latitude" id="latitude">
  46. </label>
  47. </p>
  48. <p>
  49. <input type="text" name="longitude" id="longitude">
  50. </p>
  51. </form>
  52. <p>&nbsp;</p>
  53. </body>
  54. </html>
  55.  
  56.  
  57. Read more: http://www.linhadecodigo.com.br/artigo/3653/usando-geolocalizacao-com-html5.aspx#ixzz4vfbQ0hg3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement