get user geo position in js

Solutions on MaxInterview for get user geo position in js by the best coders in the world

showing results for - "get user geo position in js"
Gabriele
07 May 2018
1<!DOCTYPE html>
2<html lang="en">
3
4<head>
5    <meta charset="UTF-8">
6    <meta http-equiv="X-UA-Compatible" content="IE=edge">
7    <meta name="viewport" content="width=device-width, initial-scale=1.0">
8    <title>Users Position</title>
9</head>
10
11<body>
12    <div id="demo"></div>
13    <script>
14        const div = document.querySelector('div');
15        if (navigator.geolocation) {
16            navigator.geolocation.getCurrentPosition(showPosition);
17        } else {
18            div.innerHTML = 'The are not allowed your location';
19        }
20
21        function showPosition(postion) {
22            div.innerHTML = `Latitude: ${postion.coords.latitude} Longitude: ${postion.coords.longitude}`
23        }
24    </script>
25</body>
26
27</html>
similar questions
queries leading to this page
get user geo position in js