-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapbox_maps_api.html
More file actions
85 lines (70 loc) · 3.03 KB
/
Copy pathmapbox_maps_api.html
File metadata and controls
85 lines (70 loc) · 3.03 KB
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
<!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>Document</title>
<!-- this the cdn -->
<script src='https://api.mapbox.com/mapbox-gl-js/v2.13.0/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v2.13.0/mapbox-gl.css' rel='stylesheet' />
</head>
<body>
<div id='map' style='width: 100%; height: 700px;'></div>
<script src="/js/keys.js"></script>
<script src="/js/mapbox-geocoder-utils.js"></script>
<script>
// TO MAKE THE MAP APPEAR YOU MUST
// ADD YOUR ACCESS TOKEN FROM
// https://account.mapbox.com
mapboxgl.accessToken = MAPBOX_TOKEN;
const map = new mapboxgl.Map({
container: 'map', // container ID
style: 'mapbox://styles/mapbox/streets-v12', // style URL
center: [-96.796, 32.776], // starting position [lng, lat]
zoom: 10, // starting zoom
});
// let restaurant = geocode("2501 N Tryon St, Charlotte, NC 28206", MAPBOX_TOKEN);
let restaurants = [
{address: "321 W Hickory St Ste 100, Denton, TX 76201", name: "Gangnam Chicken", description: "The best chicken spot in Denton served both american themed chicken and korean themed chicken."},
{address: "201 Dallas Dr, Denton, TX 76205", name: "Tortilleria La Sabrocita", description: "Best tacos in Denton hands down."},
{address: "2215 S Loop 288, Denton, TX 76205", name: "Chiloso", description: "An authentic mexican chain that serves some of the most delicious mexican food."}
]
restaurants[1].then(function (result) {
map.setCenter([result[0], result[1]])
map.setZoom(10)
})
restaurants.forEach( function(restaurant) {
const location = geocode(restaurant.address, MAPBOX_TOKEN);
location.then(function (result) {
const marker = new mapboxgl.Marker()
.setLngLat([result[0], result[1]])
.addTo(map)
const popup = new mapboxgl.Popup()
.setHTML("<h3>" + restaurant.name + "</h3><br><p>" + restaurant.description + "</p>")
marker.setPopup(popup)
})
})
// //This creates a marker for the map
// const marker1 = new mapboxgl.Marker()
// //sets the location for the marker
// .setLngLat([-96.795, 32.775])
// //attaches the marker to the map
// .addTo(map);
// const popup = new mapboxgl.Popup()
// .setLngLat([-96.763, 32.774])
// .setHTML("<p> Cool map stuff!!</p>")
// marker1.setPopup(popup)
// let newLocation = geocode("Anchorage", MAPBOX_TOKEN);
// newLocation.then(function (result) {
// console.log(result);
// map.setCenter([result[0], result[1]])
// })
// let reverseLocation = reverseGeocode({lng: 149.474, lat: 45.69}, MAPBOX_TOKEN)
// console.log(reverseLocation);
// reverseLocation.then(function (result) {
// map.setCenter([149.474, 45.69])
// })
</script>
</body>
</html>