-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
37 lines (26 loc) · 838 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
mapboxgl.accessToken =
"pk.eyJ1IjoidmFydW5zaDE3IiwiYSI6ImNrc2Fvd20xYjFobTEydW9jOXJoZWI0NjIifQ.mICrgxyasmwG-Ncm_3WGpg";
navigator.geolocation.getCurrentPosition(successLocation, error, {
enableHighAccuracy: true,
})
function successLocation(position) {
console.log(position)
setupMap([position.coords.longitude, position.coords.latitude])
}
function error() {
setupMap([139.6455, 35.8616])
}
function setupMap(center) {
const map = new mapboxgl.Map({
container: "map",
style: "mapbox://styles/mapbox/streets-v11",
center: center,
zoom: 15
});
const nav = new mapboxgl.NavigationControl();
map.addControl(nav, 'top-right');
var direction = new MapboxDirections({
accessToken: mapboxgl.accessToken
})
map.addControl(direction, 'top-left');
}