Created
September 20, 2015 04:29
-
-
Save EnriqueV/90cc7825720101460312 to your computer and use it in GitHub Desktop.
Ejemplo basico de api de geolocalizacion, segunda sesíon desarrollo de apps para firefox os
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="out"></p> | |
<button onclick="geoFind()">¿Donde estoy?</button> | |
<div id="mapa"></div> | |
<script> | |
var x = document.getElementById("out"); | |
function geoFind() { | |
if (navigator.geolocation) { | |
navigator.geolocation.getCurrentPosition(showPosition, showError); | |
} else { | |
x.innerHTML = "tu navegador no soporta geolocalizacion"; | |
} | |
} | |
function showPosition(position) { | |
var latlon = position.coords.latitude + "," + position.coords.longitude; | |
var img_url = "http://maps.googleapis.com/maps/api/staticmap?center=" | |
+latlon+"&zoom=14&size=400x300&sensor=false"; | |
document.getElementById("mapa").innerHTML = "<img src='"+img_url+"'>"; | |
} | |
function showError(error) { | |
switch(error.code) { | |
case error.PERMISSION_DENIED: | |
x.innerHTML = "Note encontramos." | |
break; | |
case error.POSITION_UNAVAILABLE: | |
x.innerHTML = "Informacion de localizacion no disponible!" | |
break; | |
case error.TIMEOUT: | |
x.innerHTML = "Rayos! no sabemos encontrarte" | |
break; | |
case error.UNKNOWN_ERROR: | |
x.innerHTML = "a pasado algo... :(" | |
break; | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment