Created
July 6, 2017 11:50
-
-
Save bozhink/fc219c311af3c7a86cfe1d5a488dff79 to your computer and use it in GitHub Desktop.
Geo Location in HTML5
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 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