Answers for "how to get user geolocation with javascript"

0

get user geo position in js

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Users Position</title>
</head>

<body>
    <div id="demo"></div>
    <script>
        const div = document.querySelector('div');
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(showPosition);
        } else {
            div.innerHTML = 'The are not allowed your location';
        }

        function showPosition(postion) {
            div.innerHTML = `Latitude: ${postion.coords.latitude} Longitude: ${postion.coords.longitude}`
        }
    </script>
</body>

</html>
Posted by: Guest on August-17-2021
0

get user geo position in js

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Users Position</title>
</head>

<body>
    <div id="demo"></div>
    <script>
        const div = document.querySelector('div');
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(showPosition);
        } else {
            div.innerHTML = 'The are not allowed your location';
        }

        function showPosition(postion) {
            div.innerHTML = `Latitude: ${postion.coords.latitude} Longitude: ${postion.coords.longitude}`
        }
    </script>
</body>

</html>
Posted by: Guest on August-17-2021

Browse Popular Code Answers by Language