What is HTML5 Geolocation?

devquora
devquora

Posted On: Mar 20, 2024

 

HTML5 Geolocation is used to locate a user’s position
The HTML5 Geolocation API is used to get the geographical position of a user.
Since this can compromise user privacy, the position is not available unless the user approves it.

Use the getCurrentPosition() method to get the user’s position.
The example below is a simple Geolocation example returning the latitude and longitude of the user’s position:

<script>
var x=document.getElementById("demo");
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 +"
Longitude: " + position.coords.longitude;
}
</script>

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    HTML5 Interview Questions

    What is HTML5 ?

    HTML5 is the most recent version of the HTML(Hypertext Markup Language). It is a language for structuring and displaying content for the World Wide Web, a core technology of the Internet...

    HTML5 Interview Questions

    What is < !DOCTYPE>? Is it necessary to use in HTML5 ?

    The &lt; !DOCTYPE&gt; is an instruction to the web browser about what version of HTML the page is written in. AND The &l..

    HTML5 Interview Questions

    List out the new features of HTML5?

    Some of the most interesting new features in HTML5:The &lt;canvas&gt; element for 2D drawing The &lt;video&gt; and &lt..