-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.html
More file actions
144 lines (115 loc) · 3.23 KB
/
web.html
File metadata and controls
144 lines (115 loc) · 3.23 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nextbike Finder</title>
<!-- Leaflet CSS -->
<link rel="stylesheet"
href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"/>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background: #f4f6f8;
}
h1 {
margin-bottom: 10px;
}
.search-box {
margin-bottom: 15px;
}
input {
padding: 8px;
width: 200px;
font-size: 16px;
}
button {
padding: 8px 12px;
font-size: 16px;
cursor: pointer;
}
#result {
margin-top: 10px;
font-weight: bold;
}
#map {
height: 850px;
margin-top: 20px;
border-radius: 8px;
}
</style>
</head>
<body>
<h1>🚲 Nextbike Finder</h1>
<div class="search-box">
<input type="text" id="bikeNumber" placeholder="Bike Nummer eingeben">
<button onclick="searchBike()">Suchen</button>
</div>
<div id="result"></div>
<div id="map"></div>
<!-- Leaflet JS -->
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script>
const API_URL =
"https://maps.nextbike.net/maps/nextbike-live.json?city=685&domains=dx&list_cities=0&bikes=0";
let map = L.map('map').setView([51.1657, 10.4515], 6); // Deutschland als Start
let marker;
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap'
}).addTo(map);
async function searchBike() {
const bikeNumber = document.getElementById("bikeNumber").value.trim();
const resultDiv = document.getElementById("result");
resultDiv.innerHTML = "Suche läuft...";
try {
const response = await fetch(API_URL);
const data = await response.json();
const result = findBike(data, bikeNumber);
if (result) {
resultDiv.innerHTML = `
✅ Bike gefunden!<br>
Stadt: ${result.city}<br>
Station: ${result.place_name}<br>
Verfügbare Räder: ${result.available_bikes}
`;
if (marker) {
map.removeLayer(marker);
}
marker = L.marker(result.coordinates).addTo(map)
.bindPopup(`
<b>${result.place_name}</b><br>
${result.city}
`)
.openPopup();
map.setView(result.coordinates, 16);
} else {
resultDiv.innerHTML = "❌ Bike nicht gefunden.";
}
} catch (error) {
resultDiv.innerHTML = "Fehler beim Laden der Daten.";
console.error(error);
}
}
function findBike(data, bikeNumber) {
for (const country of data.countries || []) {
for (const city of country.cities || []) {
for (const place of city.places || []) {
const bikeNumbers = place.bike_numbers || [];
if (bikeNumbers.includes(bikeNumber)) {
return {
city: city.name,
place_name: place.name,
available_bikes: place.bikes_available_to_rent,
coordinates: [place.lat, place.lng]
};
}
}
}
}
return null;
}
</script>
</body>
</html>