Get Your Geo Location
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Geo Location</title>
<style>
body {
font-family: 'Courier New', Courier, monospace;
}
button {
font-size: 18px;
padding: 10px 5px;
cursor: pointer;
}
</style>
</head>
<body>
<div>
<h3>Click the button to get your coordinates.</h3>
<button onclick="getLocation()">Know Your Geo Location...</button>
<h1>Latitude : <span id="lan"></span></h1>
<h1>Longitude : <span id="lon"></span></h1>
</div>
<!-- ################################################# -->
<!-- ################## JavaScript ################### -->
<!-- ################################################# -->
<script>
var lan = document.getElementById("lan");
var lon = document.getElementById("lon");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
lan.innerText = position.coords.latitude;
lon.innerText = position.coords.longitude;
}
</script>
</body>
</html>
Comments
Post a Comment