Last active
December 13, 2015 20:08
-
-
Save emedinaa/4967607 to your computer and use it in GitHub Desktop.
Html5 Geolocation - GDG Girls - Ejemplo 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<p id="geo">Click para saber tus coordenadas</p> | |
<button onClick="getLocation()"> Aqui</button> | |
<script type="text/javascript"> | |
var geo=document.getElementById("geo"); | |
function getLocation() | |
{ | |
//navigator esta permitido la geolocalización | |
if(navigator.geolocation) | |
{ | |
//genial se donde estas | |
console.log("genial se donde estas"); | |
navigator.geolocation.getCurrentPosition(showPosition,showError); | |
}else | |
{ | |
//on tas? console.log("on ta BB"); | |
geo.innerHTML="No esta soportado en este dispositivo/browser"; | |
} | |
} | |
function showPosition(position) | |
{ | |
//muestra las coordenadas | |
geo.innerHTML="Latitude "+position.coords.latitude+ | |
"<br> Longitude "+position.coords.longitude; | |
} | |
function showError(error) | |
{ | |
switch(error.code) | |
{ | |
case error.PERMISSION_DENIED: | |
geo.innerHTML="Permiso Denegado"; | |
break; | |
case error.POSITION_UNAVAILABLE: | |
geo.innerHTML="No Habilitado"; | |
break; | |
case error.TIMEOUT: | |
geo.innerHTML=" time out "; | |
break; | |
case error.UNKNOWN_ERROR: | |
geo.innerHTML=" error desconocido"; | |
break; | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment