Skip to content

Instantly share code, notes, and snippets.

@dkdndes
Created January 7, 2014 09:18
Show Gist options
  • Select an option

  • Save dkdndes/8296827 to your computer and use it in GitHub Desktop.

Select an option

Save dkdndes/8296827 to your computer and use it in GitHub Desktop.
Example: Geolocation
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<p id="geo">Click the button to get your coordinates:</p>
<button onclick="getLocation()">Try It</button>
</body>
</html>
var x = document.getElementById("geo");
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment