-
Notifications
You must be signed in to change notification settings - Fork 17
weather-app update #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,21 @@ | ||
| /* Custom CSS goes here */ | ||
| body{ | ||
| height: 100vh; | ||
| } | ||
|
|
||
| .col-md-offset-4{ | ||
| text-align: center; | ||
| } | ||
|
|
||
| h1{ | ||
| margin: 35px auto; | ||
| font-size: 45px; | ||
| } | ||
|
|
||
| .row, p{ | ||
| padding: 10px; | ||
| }; | ||
|
|
||
| main{ | ||
| color: red; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,84 @@ | ||
| /* Javascript goes here! */ | ||
| console.log('Sanity Check'); | ||
|
|
||
| var mapURL; | ||
| var toF; | ||
| var thisMap; | ||
|
|
||
| $('.weather-app').css('background-color', 'rgba(255,255,255,.5)'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer you set this in the CSS and not use js to add custom styles. |
||
|
|
||
| $(document).ready(function(){ | ||
| //Initialized description | ||
| $('.description').append("<strong>Condition Outside:</strong> "); | ||
|
|
||
| $('.submission').click(function(event){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this doing anything? |
||
| event.preventDefault(); | ||
| }); | ||
|
|
||
| $('.submission').on('click', function(){ | ||
| var userInput = $('.weather-city').val(); | ||
| requestWeatherData(userInput); | ||
| console.log(userInput); | ||
| }); | ||
| }); | ||
|
|
||
| function requestWeatherData(cityName){ | ||
| //AJAX request based on user input | ||
| $.ajax({ | ||
| method: 'GET', | ||
| url: 'https://api.openweathermap.org/data/2.5/weather', | ||
| dataType:'json' , | ||
| data: 'q=' + cityName + '&APPID=461bf158b2034c572293a7dfe13219a2', | ||
| success: onSuccess, | ||
| error: onError | ||
| }); | ||
| }; | ||
|
|
||
| function onSuccess(weatherData){ | ||
| $('.results').css('display', 'block'); | ||
| $('.results-city').empty(); | ||
| $('.temperature').empty(); | ||
| $('.humidity').empty(); | ||
| $('.description').empty(); | ||
| $('.flag-icon').empty(); | ||
| $('.city-error').css('display', 'none'); | ||
|
|
||
| var toF = parseInt(((((weatherData.main.temp)-273.15)*1.8)+32)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of doing all the math, you could have also used the API which requires another parameter to be sent as data in your ajax call 'units=imperial'. Since you are serializing your form to get the data automatically, you could have added another hidden input for this |
||
| console.dir(toF); | ||
| $('.results-city').append(weatherData.name + ", " + weatherData.sys.country); | ||
| $('.temperature').append(toF + '°'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll want to look up the character code for the degree symbol. While it may work in some browsers, it will also break in a lot more. |
||
| $('.humidity').append(weatherData.main.humidity); | ||
| $('.description').append("<strong>Condition Outside:</strong> " + weatherData.weather[0].main); | ||
| $('.flag-icon').append('<img src="../../../../flag-icon-css-master/flags/4x3/' + weatherData.sys.country + '.svg" style="width:304px;height:228px;">'); | ||
| // mapURL = getWeatherMap(weatherData.coord.lon, weatherData.coord.lat) | ||
| // console.log(mapURL); | ||
| // $('body').css("backgroundImage", mapURL); | ||
| }; | ||
|
|
||
| function onError(){ | ||
| $('.results').css('display', 'none'); | ||
|
|
||
| $('.city-error').css('display', 'inline-block'); | ||
| $('.city-error').css('color', 'red'); | ||
| console.log('dangit'); | ||
| }; | ||
|
|
||
| function getWeatherMap(x, y){ | ||
| // thisMap = 'http://tile.openweathermap.org/map/clouds_new/' + '6' + '/' + x + '/' + y + '.png?appid=' + '461bf158b2034c572293a7dfe13219a2'; | ||
| thisMap = 'http://tile.openweathermap.org/map/clouds_new/6/-97.74/30.37.png?appid=461bf158b2034c572293a7dfe13219a2' | ||
| console.log(thisMap) | ||
| $.ajax({ | ||
| method: 'GET', | ||
| url: thisMap, | ||
| dataType:'json' , | ||
| // data: 'q=' + cityName + '&APPID=461bf158b2034c572293a7dfe13219a2', | ||
| success: mapSuccess, | ||
| // error: onError | ||
| }); | ||
| function mapSuccess(mapData){ | ||
| console.log(mapData); | ||
| console.log("here"); | ||
| }; | ||
| }; | ||
|
|
||
| getWeatherMap('-97.74', '30.37'); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!