Skip to content

Instantly share code, notes, and snippets.

@bozhink
Created July 6, 2017 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bozhink/fc219c311af3c7a86cfe1d5a488dff79 to your computer and use it in GitHub Desktop.
Save bozhink/fc219c311af3c7a86cfe1d5a488dff79 to your computer and use it in GitHub Desktop.
Geo Location in HTML5
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
function getLocation()
{
// Check whether browser supports Geolocation API or not
if (navigator.geolocation) { // Supported
navigator.geolocation.getCurrentPosition(getPosition);
} else { // Not supported
alert("Oop! This browser does not support HTML5 Geolocation.");
}
}
function getPosition(position)
{
document.getElementById("location").innerHTML =
"Latitude: " + position.coords.latitude + "<br>" +
"Longitude: " + position.coords.longitude;
}
</script>
<h1>Finding Me</h1>
<button onclick="getLocation()">Where am I?</button>
<p id="location"></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment