MyBB Community Forums

Full Version: Need help understanding this HTML5 Code.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey folks, 

Hope everyone's doing well.

Happened to go-through some interview articles.

Just needed an understanding, like the below code requests users' permission for accessing their coordinates via geolocation API. How many other methods there exist in Geolocation Object and what would their usage be in real-time.

<!DOCTYPE html>
<html>
<body>
<p>Click "try it" button to get your coordinates.</p>
<button onclick="getLocation()">Try It</button>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");

function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation functionality is not supported by this browser.";
}
}

function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
</script>
</body>
</html>

TIA..!