-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
34 lines (25 loc) · 974 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
let h2 = document.querySelector('h2');
var map;
function success(pos){
console.log(pos.coords.latitude, pos.coords.longitude);
h2.textContent = `Latitude: ${pos.coords.latitude}, Longitude: ${pos.coords.longitude}`;
if (map === undefined) {
map = L.map('mapid').setView([pos.coords.latitude, pos.coords.longitude], 13);
} else {
map.remove();
map = L.map('mapid').setView([pos.coords.latitude, pos.coords.longitude], 13);
}
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.marker([pos.coords.latitude, pos.coords.longitude]).addTo(map)
.bindPopup('Eu estou aqui!')
.openPopup();
}
function error(err){
console.log(err);
}
var watchID = navigator.geolocation.watchPosition(success, error, {
enableHighAccuracy: true,
timeout: 5000
});