Tạo ứng dụng Weather App
Lập trìnhXây dựng ứng dụng thời tiết sử dụng API công cộng
Hướng dẫn
Lời giải
Sử dụng OpenWeatherMap API (hoặc API miễn phí khác) để tạo ứng dụng thời tiết đơn giản
Code mẫu
<!DOCTYPE html>
<html>
<head>
<style>
.weather-card {
border: 1px solid #ddd;
padding: 20px;
margin: 20px;
border-radius: 10px;
text-align: center;
}
.error { color: red; }
</style>
</head>
<body>
<h1>Weather App</h1>
<input type="text" id="city-input" placeholder="Nhập tên thành phố...">
<button id="get-weather">Lấy thông tin thời tiết</button>
<div id="weather-result"></div>
<script>
// Sử dụng API: https://api.openweathermap.org/data/2.5/weather
// API Key demo (có thể cần đăng ký key mới)
const API_KEY = 'your_api_key_here';
const BASE_URL = 'https://api.openweathermap.org/data/2.5/weather';
// Viết code của bạn ở đây
</script>
</body>
</html>