HTML Geolocation

Last Updated:

HTML Geolocation

The HTML Geolocation is used to get the geographical location information for a client-side device.

Note: For privacy reasons, the user is asked for permission to report location information.

In the following example, the getCurrentPosition() method return the user's current position.


HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Html Geolocation will help you finding your users Location.</p> <button onclick="getMyLocation()">Click To Your Location</button> <p id="point"></p> <script> var x = document.getElementById("point"); function getMyLocation(){ 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 + "<br>Longitude: " + position.coords.longitude; } </script> </body> </html>

Browser Support

Browsergoogle chromesafarifirefoxinternet Exploreredgeoperagoogle chromesafarifirefoxedgeoperaandroid webviewsamsung internet

Share this Page

Meet the Author