-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
99 lines (72 loc) · 2.28 KB
/
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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var map = L.map('map');
map.setView([51.505, -0.09], 13);
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
navigator.geolocation.watchPosition(success, error);
let lat , lng;
function success(pos){
lat = pos.coords.latitude;
lng = pos.coords.longitude;
//map.setView([lat, lng]);
L.Routing.control({
waypoints: [
L.latLng(lat, lng),
L.latLng(lat, lng)
]
}).addTo(map);
}
function error(err){
if(err.code === 1){
alert("Please allow location access");
}
else{
alert("Cannot get current location");
}
}
// function createButton(label, container) {
// var btn = L.DomUtil.create('button', '', container);
// btn.setAttribute('type', 'button');
// btn.innerHTML = label;
// return btn;
// }
L.Routing.control({
waypoints: [
L.latLng(57.74, 11.94),
L.latLng(57.6792, 11.949)
],
routeWhileDragging: true,
geocoder: L.Control.Geocoder.nominatim()
})
.on('routeselected', function(e) {
var route = e.route;
alert('Showing route between waypoints:\n' + JSON.stringify(route.inputWaypoints, null, 2));
})
.addTo(map);
// BELOW IS THE CODE TO DISPLAY USER'S LOCATION
// navigator.geolocation.watchPosition(success, error);
// let marker, circle, zoomed;
// function success(pos){
// const lat = pos.coords.latitude;
// const lng = pos.coords.longitude;
// const accuracy = pos.coords.accuracy;
// if(marker){
// map.removeLayer(marker);
// map.removeLayer(circle);
// }
// marker = L.marker([lat, lng]).addTo(map);
// circle = L.circle([lat, lng], { radius: accuracy}).addTo(map);
// if(!zoomed){
// zoomed = map.fitBounds(circle.getBounds());
// }
// map.setView([lat, lng]);
// }
// function error(err){
// if(err.code === 1){
// alert("Please allow location access");
// }
// else{
// alert("Cannot get current location");
// }
// }