A modern, interactive web dashboard that displays real-time weather conditions, air quality data, and AI-powered city insights for cities worldwide. Built with vanilla JavaScript, HTML5, and CSS3.
The Smart City Dashboard is a comprehensive data visualization tool that fetches live environmental data from multiple APIs and presents it in an intuitive, user-friendly interface. Users can search for any city globally and instantly view detailed information including weather conditions, air quality metrics, interactive maps, and AI-generated city descriptions.
- ⚡ Real-time Data: Live weather and air quality updates
- 🤖 AI-Powered Insights: Gemini AI generates comprehensive city descriptions
- 📊 Interactive Charts: Three different chart types using Chart.js
- 🗺️ Google Maps Integration: Interactive maps with markers and autocomplete
- 🎨 Modern UI/UX: Responsive design with smooth animations
- 🔄 Smart Fallbacks: Automatic fallback to secondary APIs if primary fails
- Real-time temperature and "feels like" temperature
- Current weather conditions and descriptions
- Wind speed and direction
- Humidity and atmospheric pressure
- Visibility range
- Sunrise and sunset times
- Last update timestamp
- Primary: Google Air Quality API with Universal AQI (0-500 scale)
- Fallback: OpenWeatherMap Air Pollution API
- Color-coded AQI status (Good/Moderate/Unhealthy)
- Detailed pollutant breakdown:
- PM2.5 and PM10 (Particulate Matter)
- CO (Carbon Monoxide)
- NO2 (Nitrogen Dioxide)
- O3 (Ozone)
- SO2 (Sulphur Dioxide)
- NH3 (Ammonia)
- Powered by Google Gemini API
- Comprehensive city analysis covering:
- Smart City Rating (infrastructure, connectivity, innovation)
- Information for Students (education, cost of living, safety)
- Information for Professionals (job market, career growth)
- Quality of Life metrics
- Top 3 reasons to choose the city
- Real-time data integration with weather and AQI information
- Temperature Bar Chart: Current, feels like, min, and max temperatures
- Air Quality Bar Chart: Visual breakdown of pollutants and AQI indexes
- Weather Metrics Radar Chart: Multi-dimensional view of humidity, cloudiness, wind, visibility, and pressure
- Interactive Google Maps with city location markers
- Google Places Autocomplete for intelligent city search
- Geocoding for accurate coordinate mapping
- Location details (coordinates, timezone, formatted address)
- Clickable markers with info windows
- Multi-Section Dashboard: Navigate between Dashboard, Charts, Map View, and Raw Data
- Live Clock: Real-time date and time display
- JSON Viewer: View complete API responses for debugging
- Responsive Design: Works seamlessly on desktop, tablet, and mobile
- Error Handling: Graceful fallbacks and user-friendly error messages
- HTML5 - Semantic markup and structure
- CSS3 - Modern styling with Grid, Flexbox, animations, and gradients
- JavaScript (ES6+) - Async/await, Fetch API, DOM manipulation
- Chart.js v4.4.0 - Data visualization and charting
- Google Maps JavaScript API - Interactive maps and geocoding
- Google Places API - Autocomplete search functionality
-
Google Maps Platform
- Maps JavaScript API - Interactive maps
- Geocoding API - City name to coordinates conversion
- Places API (Autocomplete) - Intelligent search suggestions
- Air Quality API - Real-time AQI data with multiple indexes
-
Google Gemini API
- Generative AI for city descriptions
- Multiple model fallbacks (gemini-1.5-flash, gemini-1.5-pro, etc.)
- OpenWeatherMap
- Current Weather API - Temperature, humidity, wind, etc.
- Air Pollution API - Backup AQI data
Project_Source/
│
├── index.html # Main HTML structure
├── style.css # All styling and responsive design
├── script.js # JavaScript logic and API integration (1687 lines)
├── config.js # API keys configuration (DO NOT COMMIT - in .gitignore)
├── config.example.js # Template for config.js (safe to commit)
├── build-config.js # Netlify build script (generates config.js from env vars)
├── .gitignore # Git ignore rules (protects sensitive files)
├── DEPLOYMENT.md # Detailed deployment guide
└── README.md # This file
- A modern web browser (Chrome, Firefox, Safari, Edge)
- API keys for:
- Google Maps Platform (for Maps, Geocoding, Places, and Air Quality APIs)
- Google Gemini API (for AI descriptions)
- OpenWeatherMap API (as fallback)
-
Clone or download the repository
git clone <your-repo-url> cd Project_Source
-
Set up API configuration
cp config.example.js config.js
-
Add your API keys to
config.jsconst API_CONFIG = { googleMaps: { key: "YOUR_GOOGLE_MAPS_API_KEY_HERE", // ... }, googleAirQuality: { key: "YOUR_GOOGLE_MAPS_API_KEY_HERE", // Same as Maps // ... }, gemini: { key: "YOUR_GEMINI_API_KEY_HERE", // ... }, openWeather: { key: "YOUR_OPENWEATHER_API_KEY_HERE", // ... } };
-
Open the application
- Option 1: Simply open
index.htmlin your browser - Option 2: Use a local server:
# Python 3 python -m http.server 8000 # Node.js (if you have http-server installed) npx http-server # Then navigate to http://localhost:8000
- Option 1: Simply open
-
Start using the dashboard
- Type a city name in the search bar (e.g., "New York", "London", "Tokyo")
- Click "Search" or press Enter
- Explore the Dashboard, Charts, Map View, and Raw Data sections
- Visit Google Cloud Console
- Create a new project or select an existing one
- Enable the following APIs:
- Maps JavaScript API
- Geocoding API
- Places API
- Air Quality API
- Create credentials (API Key)
- Restrict the API key to specific APIs and domains for security
- Visit Google AI Studio
- Sign in with your Google account
- Click "Create API Key"
- Copy the generated key
- Visit OpenWeatherMap
- Sign up for a free account
- Navigate to API keys section
- Copy your default key or create a new one
User types city name
↓
Google Places Autocomplete (suggests cities)
↓
User selects or enters city
↓
Google Geocoding API (gets accurate coordinates)
↓
Multiple APIs called in parallel/sequence
Primary Path:
1. Google Geocoding → Get coordinates
2. OpenWeatherMap → Get weather data (using coordinates)
3. Google Air Quality → Get AQI data
4. Google Gemini → Generate AI city description
5. Google Maps → Display map with marker
Fallback Path (if Google APIs fail):
1. OpenWeatherMap → Get weather (using city name)
2. OpenWeatherMap Air Pollution → Get AQI backup
3. Google Maps still attempts to load
API Response Received
↓
Parse JSON data
↓
Update DOM elements (temperature, AQI, etc.)
↓
Update Chart.js charts
↓
Update Google Map marker
↓
Generate and display AI description
Maps JavaScript API:
https://maps.googleapis.com/maps/api/js?key={KEY}&libraries=places
Geocoding API:
https://maps.googleapis.com/maps/api/geocode/json?latlng={lat},{lng}&key={KEY}
Air Quality API:
POST https://airquality.googleapis.com/v1/currentConditions:lookup?key={KEY}
Body: { "location": { "latitude": lat, "longitude": lon } }
Gemini API:
POST https://generativelanguage.googleapis.com/v1/models/{MODEL}:generateContent?key={KEY}
Body: {
"contents": [{ "parts": [{ "text": "prompt" }] }],
"generationConfig": { ... }
}
Current Weather:
GET https://api.openweathermap.org/data/2.5/weather?q={city}&appid={KEY}&units=metric
GET https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid={KEY}&units=metric
Air Pollution:
GET https://api.openweathermap.org/data/2.5/air_pollution?lat={lat}&lon={lon}&appid={KEY}
- Modern Gradient Background: Purple to blue gradient for visual appeal
- Card-Based Layout: Clean, organized sections with shadows and rounded corners
- Color-Coded AQI:
- Green (0-50): Good air quality
- Orange (51-150): Moderate/Unhealthy for sensitive
- Red (151+): Unhealthy/Hazardous
- Smooth Animations: Chart animations, section transitions, fade effects
- Responsive Grid: Adapts to different screen sizes
- Professional Typography: Clear hierarchy and readable fonts
-
Temperature Bar Chart (
tempChart)- Type: Bar chart
- Data: Current, Feels Like, Min, Max temperatures
- Colors: Purple/blue gradient
- Animation: 1.5s ease-in-out
-
Air Quality Bar Chart (
aqiChart)- Type: Bar chart
- Data: Pollutant concentrations or AQI indexes
- Colors: Dynamic based on values (green/orange/red)
- Animation: 1.5s ease-in-out
-
Weather Metrics Radar Chart (
weatherChart)- Type: Radar/Spider chart
- Data: Normalized values for humidity, cloudiness, wind, visibility, pressure
- Colors: Purple theme
- Animation: 2s ease-in-out
- ✅
config.jsis in.gitignore- never commit your API keys - ✅ Use
config.example.jsas a template for others - ✅ For production, use environment variables (see DEPLOYMENT.md)
- ✅ Restrict API keys in Google Cloud Console:
- Limit to specific APIs
- Add HTTP referrer restrictions
- Set usage quotas
- Never expose API keys in client-side code for production apps (consider a backend proxy)
- Regularly rotate API keys
- Monitor API usage in Google Cloud Console
- Use separate API keys for development and production
See DEPLOYMENT.md for detailed deployment instructions.
- Push code to GitHub (config.js is already ignored)
- Connect repository to Netlify
- Add environment variables in Netlify dashboard:
GOOGLE_MAPS_KEYGEMINI_KEYOPENWEATHER_KEY
- Netlify will auto-generate
config.jsduring build usingbuild-config.js
"Configuration file missing" error
- Solution: Create
config.jsfromconfig.example.jsand add your API keys
City not found
- Check spelling of city name
- Try adding country code (e.g., "London, UK")
- Use major city names for better results
Maps not loading
- Verify Google Maps API key is correct
- Ensure Maps JavaScript API is enabled in Google Cloud Console
- Check browser console for specific error messages
AI description not generating
- Verify Gemini API key is correct
- Check if Generative AI API is enabled
- Review browser console for API errors
- Ensure API quota hasn't been exceeded
Charts not displaying
- Check if Chart.js CDN is loading (inspect Network tab)
- Verify data is being fetched (check Raw Data section)
- Open browser console for JavaScript errors
401/403 API Errors
- API key may need 1-2 hours to activate after creation
- Verify API key restrictions allow your domain
- Check if required APIs are enabled in Google Cloud Console
Rate Limit Errors
- Free tier has usage limits
- Wait a few minutes before retrying
- Consider upgrading API quotas if needed
Initialization:
init()- Page load initializationinitGoogleMaps()- Google Maps API callbackloadGoogleMapsAPI()- Dynamic script loading
Data Fetching:
searchCity()- Entry point for city searchgeocodeCityForData()- Get coordinates from GooglefetchWeatherData()- Fetch weather from OpenWeatherMapfetchWeatherDataByCoordinates()- Weather fetch using coordinatesfetchAirQualityData()- Primary Google Air Quality APIfetchAirQualityDataOpenWeather()- Fallback AQIgenerateCityDescription()- AI-powered descriptions
Display Updates:
updateWeatherDisplay()- Update weather UI elementsupdateAirQualityDisplay()- Update AQI displayupdateAirQualityDisplayGoogle()- Google AQI displayupdateCharts()- Update all Chart.js visualizationsupdateGoogleMap()- Update map location and marker
Chart Functions:
updateTemperatureChart()- Bar chart for temperaturesupdateAirQualityChart()- Bar chart for air qualityupdateWeatherMetricsChart()- Radar chart for weather metrics
currentCity- Currently selected city nameweatherData- Current weather data objectairQualityData- Current AQI data objectmap- Google Maps instancemarker- Current map markerautocomplete- Google Places Autocomplete instancetempChart,aqiChart,weatherChart- Chart.js instances
- 7-day weather forecast
- Historical data trends
- Multiple city comparison
- Export data as CSV/JSON
- Dark mode theme toggle
- Geolocation auto-detect
- Weather alerts and notifications
- Favorite cities bookmark
- Share city data via URL
- Multi-language support
- Add backend API proxy for enhanced security
- Implement caching for API responses
- Add unit tests
- Optimize bundle size
- Add service worker for offline support
- Implement Progressive Web App (PWA) features
This project is created for educational purposes.
- Weather Data: OpenWeatherMap API (fallback)
- Maps & Air Quality: Google Maps Platform
- AI Descriptions: Google Gemini API
- Data Visualization: Chart.js library
- Design Inspiration: Modern dashboard UI/UX patterns
Built with for Smart City Data Visualization
Last Updated: December 2024