-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracking.html
83 lines (72 loc) · 2.33 KB
/
tracking.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
77
78
79
80
81
82
83
<!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>Map</title>
<link
href="https://api.mapbox.com/mapbox-gl-js/v2.8.1/mapbox-gl.css"
rel="stylesheet"
/>
</head>
<body>
<div class="coordinates"></div>
<div id="map" style="width: 100vw; height: 100vh"></div>
<script src="https://api.mapbox.com/mapbox-gl-js/v2.8.1/mapbox-gl.js"></script>
<script>
mapboxgl.accessToken =
"pk.eyJ1IjoidGVjaGVmZmluIiwiYSI6ImNsMnVsemZiNTAzY2EzaW1wZ2kwZnVvMHYifQ.HvolRXL1kXo6te0fkz27TQ";
let options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0,
};
const success = (pos) => {
document.querySelector(".coordinates").innerText =
pos.coords.longitude + "," + pos.coords.latitude;
var map = new mapboxgl.Map({
container: "map",
style: "mapbox://styles/mapbox/streets-v11",
center: [pos.coords.longitude, pos.coords.latitude],
zoom: 15,
});
// Create a default Marker, colored black, rotated 45 degrees.
// const marker2 = new mapboxgl.Marker({ color: "black", rotation: 45 })
const marker2 = new mapboxgl.Marker({ color: "black" })
.setLngLat([pos.coords.longitude, pos.coords.latitude])
.addTo(map);
map.on("load", () => {
map.addSource("route", {
type: "geojson",
data: {
type: "Feature",
properties: {},
},
});
map.addLayer({
id: "route",
type: "line",
source: "route",
layout: {
"line-join": "round",
"line-cap": "round",
},
paint: {
"line-color": "#888",
"line-width": 8,
},
});
});
};
const error = (err) => {
console.log(err);
};
navigator.geolocation.getCurrentPosition(success, error, options);
// Create a default Marker and add it to the map.
// const marker1 = new mapboxgl.Marker()
// .setLngLat([-122.483696, 37.833818])
// .addTo(map);
</script>
</body>
</html>