Horje
What is HTML Geolocation API

The HTML Geolocation API is used to locate a user's position.

The HTML Geolocation is used to get the geographical position of a user. Due to privacy concerns, this position requires user approval. Geo-location in HTML5 is used to share the location with some websites and be aware of the exact location. It is mainly used for local businesses, and restaurants, or showing locations on the map. It uses JavaScript to give latitude and longitude to the backend server.

Most browsers support Geolocation API. Geo-location API uses a global navigator object. In this article, we will know HTML Geolocation, various properties, methods & their implementation through examples.

Syntax:

var loc = navigator.geolocation

 


Example of HTML Geolocation API

Try following Example
index.html
Example: HTML

<!DOCTYPE html>
<html>
 
<body>
    <p>Displaying location using Latitude and Longitude</p>
 
    <button class="geeks" onclick="getlocation()">
        Click Me
    </button>
    <p id="demo1"></p>
 
    <script>
        let variable1 = document.getElementById("demo1");
        function getlocation() {
            navigator.geolocation.getCurrentPosition(showLoc);
        }
        function showLoc(pos) {
            variable1.innerHTML =
                "Latitude: " +
                pos.coords.latitude +
                "<br>Longitude: " +
                pos.coords.longitude;
        }
    </script>
</body>
   
</html>






Related Articles
What is HTML Geolocation API HTML Geolocation API
How to create HTML Locate the User's Position HTML Geolocation API
What type of browsers will support for HTML Geo Location HTML Geolocation API
How to Use HTML Geolocation HTML Geolocation API
How to add Handling Errors and Rejections HTML Geolocation API
What is Location-specific Information HTML Geolocation API
How to create HTML getCurrentPosition() Method - Return Data HTML Geolocation API
How to create HTML Geolocation Object - Other interesting Methods HTML Geolocation API

Single Articles
Example of HTML Geolocation APIHTML Geolocation API

Read Full:
HTML Geolocation API
Category:
Web Tutorial
Sub Category:
HTML Geolocation API
Uploaded by:
Admin
Views:
288


Reffered: https://www.geeksforgeeks.org/html-geolocation/