Skip to content

Instantly share code, notes, and snippets.

@carlosrojaso
Created May 12, 2014 07:23
Show Gist options
  • Save carlosrojaso/085ddecd6faee54064c8 to your computer and use it in GitHub Desktop.
Save carlosrojaso/085ddecd6faee54064c8 to your computer and use it in GitHub Desktop.
geolocation
<!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