Last active
December 13, 2015 20:08
-
-
Save emedinaa/4967623 to your computer and use it in GitHub Desktop.
Html5 Geolocation - GDG Girls - Ejemplo 3
This file contains 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> | |
<div id="mapholder"></div> | |
<script type="text/javascript"> | |
var geo=document.getElementById("geo"); | |
var holder=document.getElementById("mapholder"); | |
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; | |
var latlon=position.coords.latitude+","+ | |
position.coords.longitude; | |
//servicio google maps imagen | |
var img="http://maps.googleapis.com/maps/api/staticmap?center="+latlon+"&zoom=14&size=400x300&sensor=false"; | |
holder.innerHTML="<img src='"+img+"'>"; | |
} | |
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