Weather App
How do I make an weather app?
Local weather app using jQuery and the browser's geo-location.. What is a weather app? How do you make a weather app? This script and codes were developed by Katie Inkblotty on 08 August 2022, Monday.
Weather App - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Weather App</title> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="toggleSys"> <div id="metric">Metric</div> <span>|</span> <div id="imp">Imperial</div>
</div>
<div class="container"> <h4 id="error"><i class="fa fa-spinner fa-spin"></i></h4> <div id="city"></div> <div id="cond"></div> <div id="temp"></div> <div id="humid"></div> <div id="wind"></div>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Weather App - Script Codes CSS Codes
body { background-color: #eee; font-family: Arial, sans-serif; font-size: 1.1em;
}
.toggleSys { margin: 0; margin-right: 2%; text-align: right;
}
.toggleSys div { border-radius: 0.5em; cursor: pointer; display: inline-block; letter-spacing: 0.1em; margin: 0; padding: 0.5% 1.75%;
}
.toggleSys div:hover { background-color: #e2e2e2;
}
.toggleSys div:active { background-color: #d1d1d1;
}
.container { margin: 2% auto 0 auto; text-align: center;
}
.container div { font-size: 1.2em; letter-spacing: 0.05em; margin-bottom: 0.9em;
}
.container #city { font-size: 1.5em; margin-bottom: 0.5em;
}
.container #cond { margin-bottom: 2em;
}
.container #cond img { display: block; margin: 0 auto; width: 5em;
}
.container #humid { margin: 1.5em auto;
}
.container #temp img { content: url("https://d30y9cdsu7xlg0.cloudfront.net/png/100988-200.png"); height: 3em; margin: -1.5em 0 -1em 0; width: auto;
}
.container #wind img { content: url("https://d30y9cdsu7xlg0.cloudfront.net/png/159100-200.png"); height: auto; margin: -1.6em -0.2em; width: 4em;
}
Weather App - Script Codes JS Codes
// weather icon is based on weather code. errors are in the code.
$('#error').html('<i class="fa-spinner fa-spin"></i>');
if ('geolocation' in navigator){ $('#error').html("<i class='fa fa-spinner fa-spin'></i><span> Finding city...<span>"); var key = '336f8a81ea71a7cbbc763c7724be5061'; var url = "http://api.openweathermap.org/data/2.5/weather"; function getLocalWeather(system) { navigator.geolocation.getCurrentPosition(function(position) { callAPI(position.coords.latitude, position.coords.longitude, system); $('#error').html(''); }) }; function callAPI(latitude, longitude, system){ $.ajax({ url: "http://api.openweathermap.org/data/2.5/weather?units=" + system + "&lat=" + latitude + "&lon=" + longitude + "&appid=" + key, async: false }) .then(function(data){ if (data.cod === '404') { $('#error').html('Error: City not found'); } else { if ( system === 'metric' ) { var tempSuff = '° C'; var windSuff = "meters/sec"; } else { var tempSuff = '° F'; var windSuff = "miles/hr"; } var weatherIcon; if ( data.cod === 800 ) { // sunny weatherIcon = "<img src='https://d30y9cdsu7xlg0.cloudfront.net/png/211200-200.png' alt='sun icon'></img>" } else { switch(data.cod.toString()[0]){ case '2': weatherIcon = '<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/211759-200.png" alt="thunderstorm icon"></img>'; break; case '3': weatherIcon = '<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/211199-200.png" alt="rainy icon"></img>'; break; case '5': weatherIcon = '<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/211199-200.png" alt="rainy icon"></img>'; break; case '6': weatherIcon = '<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/211198-200.png" alt="snow icon"></img>'; break; case '7': weatherIcon = '<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/211201-200.png" alt="fog icon"></img>'; break; case '8': weatherIcon = '<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/211206-200.png" alt="cloud icon"></img>'; break; case '9': weatherIcon = '<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/211740-200.png" alt="extreme weather icon"></img>'; break; default: console.log('unable to find weather icon'); } }; $('#city').html(data.name); $('#cond').html(weatherIcon + data.weather[0].description); $('#temp').html('<img alt="temperature thermometer icon"></img>' + data.main.temp + tempSuff); $('#humid').html(data.main.humidity + "% Humidity"); $('#wind').html("<img alt='wind icon'></img>" + data.wind.speed + " " + windSuff); } }) }; getLocalWeather('metric'); $('#metric').on('click', function(){ getLocalWeather('metric') }); $('#imp').on('click', function(){ getLocalWeather('imperial') });
} else { $('#error').html("Sorry, geolocation is not enabled in your browser. We can't find your weather if we can't find you!");
}
Developer | Katie Inkblotty |
Username | inkblotty |
Uploaded | August 08, 2022 |
Rating | 3 |
Size | 3,881 Kb |
Views | 42,504 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Twitch Live Channels | 4,956 Kb |
Simon game | 5,088 Kb |
Google Calendar Event Feed | 2,135 Kb |
React Recipe Box | 13,583 Kb |
Tic Tac Toe | 4,161 Kb |
Star Wars search | 3,521 Kb |
GeoLocation | 1,752 Kb |
Camper News Clone | 3,690 Kb |
Portfolio Clone for FreeCodeCamp | 5,223 Kb |
Le Fake Bakery | 4,699 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Cartoon Bomb | Tcmulder | 4,929 Kb |
Minimal Menu | Achudars | 3,430 Kb |
Video mute | Leon9208 | 2,131 Kb |
Speech bubbles | Something | 1,547 Kb |
Birthday Party Starter | Aussieyang | 1,629 Kb |
GLSL Hills | Ykob | 6,991 Kb |
A Pen by Shidhin | Shidhincr | 5,015 Kb |
Pure CSS Tooltips | Mobius1 | 2,271 Kb |
Wip elementary os navbar | Nickcolley | 2,993 Kb |
Drag and Drop Quiz | Cgspicer | 3,837 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!