-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
76 lines (59 loc) · 1.88 KB
/
index.html
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Realtime location tracker</title>
<!-- leaflet css -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
<style>
body {
margin: 0;
padding: 0;
}
#map {
width: 100%;
height: 100vh;
}
</style>
</head>
<body>
<div id="map"></div>
</body>
</html>
<!-- leaflet js -->
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<script>
// Map initialization
var map = L.map('map').setView([-6.238008040299108, 106.99211961629807], 6);
//osm layer
var osm = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
});
osm.addTo(map);
if(!navigator.geolocation) {
console.log("Your browser doesn't support geolocation feature!")
} else {
setInterval(() => {
navigator.geolocation.getCurrentPosition(getPosition)
}, 1000);
}
var marker, circle;
function getPosition(position){
// console.log(position)
var lat = position.coords.latitude
var long = position.coords.longitude
var accuracy = position.coords.accuracy
if(marker) {
map.removeLayer(marker)
}
if(circle) {
map.removeLayer(circle)
}
marker = L.marker([lat, long])
circle = L.circle([lat, long], {radius: accuracy})
var featureGroup = L.featureGroup([marker, circle]).addTo(map)
map.fitBounds(featureGroup.getBounds())
console.log("Your coordinate is: Lat: "+ lat +" Long: "+ long+ " Accuracy: "+ accuracy)
}
</script>