-
Notifications
You must be signed in to change notification settings - Fork 1
/
CTA.js
61 lines (54 loc) · 1.87 KB
/
CTA.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
// Initialize Mapbox
mapboxgl.accessToken =
"pk.eyJ1IjoibWlyYXptb25kYWwiLCJhIjoiY2xpZzdxYWk2MG12bjNxbXJyYzBqMzA5eSJ9.amL4kvoEwsBed9Iab5kyEg";
const map = new mapboxgl.Map({
container: "map",
style: "mapbox://styles/mapbox/streets-v11",
center: [-74.5, 40],
zoom: 9,
});
// Get user's location
navigator.geolocation.getCurrentPosition((position) => {
const userLocation = [position.coords.longitude, position.coords.latitude];
// Set map center to user's location
map.setCenter(userLocation);
// Add user marker to map
new mapboxgl.Marker().setLngLat(userLocation).addTo(map);
// Fetch nearby clubs using Places API
fetch(
`https://api.mapbox.com/geocoding/v5/mapbox.places/clubs.json?proximity=${userLocation[0]},${userLocation[1]}&access_token=${mapboxgl.accessToken}`
)
.then((response) => response.json())
.then((data) => {
const clubs = data.features;
// Add club markers to map
clubs.forEach((club) => {
new mapboxgl.Marker().setLngLat(club.geometry.coordinates).addTo(map);
});
// Display club list
const clubList = document.getElementById("clubs");
clubs.forEach((club) => {
const clubItem = document.createElement("li");
clubItem.classList.add("club-item");
clubItem.textContent = club.text;
clubList.appendChild(clubItem);
});
});
});
// Search Bar
function myFunction() {
let input, filter, ul, li, a, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
ul = document.getElementById("myUL");
li = ul.getElementsByTagName("li");
for (i = 0; i < li.length; i++) {
a = li[i].getElementsByTagName("a")[0];
txtValue = a.textContent || a.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = "";
} else {
li[i].style.display = "none";
}
}
}