Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <title>geolocation</title>
- <link rel="stylesheet" href="">
- </head>
- <body onload="init()">
- <h1>html5</h1>
- <span class="info">
- <p id="status">html5 geolocation</p>
- </span>
- <h2>Position atual</h2>
- <table border="1">
- <thead>
- <tr>
- <td width="40" scope="col"><h2 align="left">Latitude</h2></td>
- <td id="latitude"></td
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><h2>Longitutude</h2></td>
- <td id="longitude"></td>
- </tr>
- <tr>
- <td><h2>Precisao</h2></td>
- <td id="accuracy"></td>
- </tr>
- </tbody>
- </table>
- <p id="link"></p>
- </body>
- </html>
- <script type="text/javascript">
- function init(){
- loadPosition();
- }
- function loadPosition(){
- //se navegador comportar
- if(navigator.geolocation){
- document.getElementById("status").
- innerHTML ="Seu browser tem suporte ao HTML5 - geolocation"
- //pegar posicao do cara
- navigator.geolocation.getCurrentPosition(updateLocation, handlerLocationError);
- }
- }
- function updateLocation(position){
- var latitude = position.coords.latitude;
- var longitude = position.coords.longitude;
- var precisao = position.coords.accuracy;
- alert("Latitude:"+latitude+"- longitude"+longitude+"precisao"+precisao);
- document.getElementById("latitude").innerHTML = latitude;
- document.getElementById("latitude").innerHTML = longitude;
- document.getElementById("accuracy").innerHTML = precisao;
- document.getElementById("link").
- innerHTML = '<a href="https://google.com/maps/dir/'+
- latitude + ',' + longitude+'/Rua Tiburcio Pedro Ferreira,55 - Centro" target="_Blank">Como chegar</a>';
- }
- function handlerLocationError(erro){
- swicth(erro.code){
- case 0:
- alert("Erro ao atualizar a posição atual. Erro:"+erro.message);
- break;
- case 1:
- alert("Usuario nao compartilhou a localização");
- break;
- case 2:
- alert("O browser não está habilitado para geolocalização. ERRO:"+erro.message);
- break;
- case 3:
- alert("Tempo Esgotado para tentativa de localização");
- break;
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement