-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapbox_maps_api.html
More file actions
105 lines (90 loc) · 3.11 KB
/
mapbox_maps_api.html
File metadata and controls
105 lines (90 loc) · 3.11 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Favorite Restuartants</title>
<script src='https://api.mapbox.com/mapbox-gl-js/v2.5.0/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v2.5.0/mapbox-gl.css' rel='stylesheet' />
<style>
#map {
width: 500px;
height: 500px;
margin: auto;
}
</style>
</head>
<body>
<h1>Mapbox of My Favorite Eats</h1>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="keys.js"></script>
<script src="js/mapbox-geocoder-utils.js"></script>
<div id="map"></div>
<script>
mapboxgl.accessToken = mapboxApiKey;
var map = new mapboxgl.Map({
container: "map",
style: "mapbox://styles/mapbox/satellite-streets-v11",
zoom: 10,
center: [-98.58820828429351, 29.55837877334802]
});
var favRestaurantItem = [
{name: "Carraba's",
address: "12507 I-10 West, San antonio, Texas 78230"},
{name: "Max and Louies",
address: "226 W Bitters Ste 126, San antonio, Texas 78216"},
{name: "Jacala Mexican Restaurant",
address: "606 West Ave, San antonio, Texas 78201"}
];
geocode(favRestaurantItem[0].address,mapboxApiKey).then(function(result) {
map.setCenter(result);
var marker = new mapboxgl.Marker()
.setLngLat(result)
.addTo(map);
var favPopup = new mapboxgl.Popup()
.setHTML("<p>" + input.name +"</p>")
marker.setPopup(favPopup)
})
// console.log(result);
// map.setCenter(result);
// map.setZoom(18);
// })
// reverseGeocode({lng: 98.58820828429351, lat: 29.55837877334802},mapboxApiKey).then(function(results) {
// console.log(results);
// })
favRestaurantItem.forEach(function (input) {
geocode(favRestaurantItem[0].address,mapboxApiKey).then(function(result) {
map.setCenter(result);
var marker = new mapboxgl.Marker()
.setLngLat(result)
.addTo(map);
var favPopup = new mapboxgl.Popup()
.setHTML("<p>" + input.name +"</p>")
marker.setPopup(favPopup)
})
})
// var marker1 = new mapboxgl.Marker({
// color: "red"
// })
// .setLngLat([-98.58820828429351, 29.55837877334802])
// .setPopup(new mapboxgl.Popup()
// .setHTML("<p>Carraba's Italian Grill Favorite</p>"))
// .addTo(map)
//
// var marker2 = new mapboxgl.Marker({
// color: "blue"
// })
// .setLngLat([-98.48618125142433, 29.571872315220997])
// .setPopup(new mapboxgl.Popup()
// .setHTML("<p>Max and Louie's New York Diner Second Fav.</p>"))
// .addTo(map)
//
// var marker3 = new mapboxgl.Marker({
// color: "green"
// })
// .setLngLat([-98.5255391164348, 29.470738057554264])
// .setPopup(new mapboxgl.Popup()
// .setHTML("<p>Jacala Mexican Restaurant Third Fav.</p>"))
// .addTo(map)
</script>
</body>
</html>