-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
31 lines (26 loc) · 865 Bytes
/
script.js
File metadata and controls
31 lines (26 loc) · 865 Bytes
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
mapboxgl.accessToken = 'pk.eyJ1IjoiY2hlcGtvZWNoIiwiYSI6ImNrejZ4cHZnajBnM28yd3M4cmhrZTlrYmwifQ.rqWbVVGU9iv13Mg067jCIQ';
navigator.geolocation.getCurrentPosition(successLocation, errorLocation,{ enableHighAccuracy:true
})
function successLocation(position){
console.log(position)
setupMap([position.coords.longitude, position.coords.latitude])
}
function errorLocation(){
setupMap([1.2921,36.8219])
}
function setupMap(center){
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v11',
center:center,
zoom: 15
})
map.addControl(new mapboxgl.NavigationControl());
mapboxgl.accessToken = 'pk.eyJ1IjoiY2hlcGtvZWNoIiwiYSI6ImNrejZ4cHZnajBnM28yd3M4cmhrZTlrYmwifQ.rqWbVVGU9iv13Mg067jCIQ';
map.addControl(
new MapboxDirections({
accessToken: mapboxgl.accessToken
}),
'top-left'
);
}