Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <title>geolocation</title>
  7. <link rel="stylesheet" href="">
  8. </head>
  9. <body onload="init()">
  10. <h1>html5</h1>
  11.  
  12. <span class="info">
  13. <p id="status">html5 geolocation</p>
  14. </span>
  15.  
  16. <h2>Position atual</h2>
  17. <table border="1">
  18. <thead>
  19. <tr>
  20. <td width="40" scope="col"><h2 align="left">Latitude</h2></td>
  21. <td id="latitude"></td
  22. </tr>
  23. </thead>
  24. <tbody>
  25. <tr>
  26. <td><h2>Longitutude</h2></td>
  27. <td id="longitude"></td>
  28. </tr>
  29. <tr>
  30. <td><h2>Precisao</h2></td>
  31. <td id="accuracy"></td>
  32. </tr>
  33. </tbody>
  34. </table>
  35. <p id="link"></p>
  36. </body>
  37. </html>
  38. <script type="text/javascript">
  39. function init(){
  40. loadPosition();
  41. }
  42. function loadPosition(){
  43. //se navegador comportar
  44. if(navigator.geolocation){
  45. document.getElementById("status").
  46. innerHTML ="Seu browser tem suporte ao HTML5 - geolocation"
  47. //pegar posicao do cara
  48. navigator.geolocation.getCurrentPosition(updateLocation, handlerLocationError);
  49. }
  50. }
  51. function updateLocation(position){
  52. var latitude = position.coords.latitude;
  53. var longitude = position.coords.longitude;
  54. var precisao = position.coords.accuracy;
  55.  
  56. alert("Latitude:"+latitude+"- longitude"+longitude+"precisao"+precisao);
  57.  
  58. document.getElementById("latitude").innerHTML = latitude;
  59. document.getElementById("latitude").innerHTML = longitude;
  60. document.getElementById("accuracy").innerHTML = precisao;
  61.  
  62. document.getElementById("link").
  63. innerHTML = '<a href="https://google.com/maps/dir/'+
  64. latitude + ',' + longitude+'/Rua Tiburcio Pedro Ferreira,55 - Centro" target="_Blank">Como chegar</a>';
  65. }
  66. function handlerLocationError(erro){
  67. swicth(erro.code){
  68. case 0:
  69. alert("Erro ao atualizar a posição atual. Erro:"+erro.message);
  70. break;
  71. case 1:
  72. alert("Usuario nao compartilhou a localização");
  73. break;
  74. case 2:
  75. alert("O browser não está habilitado para geolocalização. ERRO:"+erro.message);
  76. break;
  77. case 3:
  78. alert("Tempo Esgotado para tentativa de localização");
  79. break;
  80. }
  81. }
  82. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement