Created
May 12, 2014 07:23
-
-
Save carlosrojaso/085ddecd6faee54064c8 to your computer and use it in GitHub Desktop.
geolocation
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="demo">Click the button to get your coordinates:</p> | |
<button onclick="getLocation()">Try It</button> | |
<script> | |
var x=document.getElementById("demo"); | |
function getLocation() | |
{ | |
if (navigator.geolocation) | |
{ | |
navigator.geolocation.getCurrentPosition(showPosition); | |
} | |
else{x.innerHTML="Geolocation is not supported by this browser.";} | |
} | |
function showPosition(position) | |
{ | |
x.innerHTML="Latitude: " + position.coords.latitude + | |
"<br>Longitude: " + position.coords.longitude; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment