IHYPRESS PROGRAMMING
Tutorials and JavaScript programs with code and output for beginners
c programming
HOME | ASP | C | CSS | GNUPLOT | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
arrow_circle_left
share
arrow_circle_right
JavaScript ❯ Geolocation API
<16>
<!DOCTYPE html> <html> <head> <title>Geolocation API</title> </head> <body> <button onclick="getLocation()">Get Your Coordinates</button> <p id="coords"></p> <script> const x = document.getElementById("coords"); // The getCurrentPosition() method is used to get the current position of the device. // The try/catch combo handles errors without stopping JavaScript. // The try statement defines the code block to run (to try). // The catch statement defines a code block to handle any error. function getLocation() { try { navigator.geolocation.getCurrentPosition(showPosition); } catch { x.innerHTML = "Geolocation Error!";}} function showPosition(position) { x.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude;} </script> </body> </body> </html>
Hergestellt in Deutschland / Made in Germany
Geolocation API

COPYRIGHT © 2015-2026 IHY PRESS Frankfurt am Main 60329 Deutschland