HTML Geolocation getCurrentPosition() Method Last Updated : 29 Dec, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we will know HTML Geolocation getCurrentPosition() Method, various parameters, & their implementation through the examples. HTML5 provides us the Geolocation API which helps us to identify the geographic location of the user. The Geolocation API gives the latitude and longitude of the user's current location which are further sent to the backend using JavaScript and then the current location of the user is shown on the website. The getCurrentPosition() method is used for getting the current location of the user. Syntax: navigator.geolocation.getCurrentPosition(success, error, options); Parameter values: success: It is a function that is called after the data is successfully gathered by the getCurrentPosition() method from the API.error: It is also a callback function that returns the warnings and the error messages of the location.options: It helps us to set a timeout, enableHighAccuracy, and maximumAge.Please refer to the HTML Geolocation article for the various properties, methods & their implementation in detail. Example: The below example illustrate the Geolocation getCurrentPosition() Method by checking the user’s geolocation. HTML <!DOCTYPE html> <html> <head> <title>Get Current Position</title> </head> <body> <h2>Welcome To GFG</h2> <div> <button onclick="geolocator()">click me</button> <p id="paraGraph"></p> </div> <script> var paraGraph = document.getElementById("paraGraph"); var user_loc = navigator.geolocation; function geolocator() { if(user_loc) { user_loc.getCurrentPosition(success); } else { "Your browser doesn't support geolocation API"; } } function success(data) { var lat = data.coords.latitude; var long = data.coords.longitude; paraGraph.innerHTML = "Latitude: " + lat + "<br>Longitude: " + long; } </script> </body> </html> Output: Getting the user’s current geolocation. Example 2: To Display timestamp and Accuracy. HTML <!DOCTYPE html> <html> <head> <title>Get Current Location</title> </head> <body> <h2>Welcome To GFG</h2> <div> <button onclick="geolocator()">click me</button> <p id="paraGraph"></p> </div> <script> var paraGraph = document.getElementById("paraGraph"); var user_loc = navigator.geolocation; function geolocator() { if(user_loc) { user_loc.getCurrentPosition(success); } else { "Your browser doesn't support geolocation API"; } } function success(data) { var accu = data.coords.accuracy; var tmstmp = data.timestamp; paraGraph.innerHTML = "Accuracy: " + accu + "<br>Time Stamp: " + tmstmp; } </script> </body> </html> Output: Getting the timestamp and Accuracy of a userSupported Browsers: Google Chrome 5.0Microsoft Edge 12.0Internet Explorer 9.0Firefox 3.5Opera 10.6Safari 5.0 Comment More infoAdvertise with us Next Article HTML Geolocation getCurrentPosition() Method A abhisheksainiaggarwal Follow Improve Article Tags : HTML HTML-Methods Similar Reads How to get Geolocation in Python? In this article, we will discuss on how to get Geolocation when you enter any location name and it gives all the useful information such as postal code, city, state, country etc. with the latitudes and the longitudes (the specific coordinates) and vice-versa in which we provide the coordinates to ge 2 min read HTML Geolocation clearWatch() Method In this article, we will learn the HTML geolocation clearWatch() method and its implementation. The clearWatch() method is used to cancel the currently running watchPosition() call and removes the location or errors generated as a result of the previous call.Syntax:navigator.geolocation.clearWatch(c 2 min read HTML DOM Geolocation position Property The Geolocation position property in HTML DOM is used to return the position of a device on Earth. The returned Coordinates object could be used for various purposes including navigation and tracking the position of the device. Return Value: position.coords: The coordinates object that has all the i 2 min read HTML Geolocation watchPosition() Method In this article, we will discuss the Geolocation watchPosition() method. Geolocation in HTML is used to register a handler function that will be called automatically each time the position of the device changes. Syntax: navigator.geolocation.watchPosition(showLoc, error, options); Parameter: showLoc 3 min read HTML DOM getBoundingClientRect() Method The HTML DOM getBoundingClientRect() Method returns the relative positioning to the viewport. It returns 8 properties: left, top, right, bottom, x, y, width, and height. Scrolling will change the position value. Syntax: let rect = div.getBoundingClientRect();Parameter: This method doesn't accept any 3 min read Like