Advertisement
Guest User

Weather Page - Updated

a guest
Mar 31st, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.86 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. #header {
  6.     background-color:black;
  7.     color:white;
  8.     text-align:center;
  9.     padding:100px;
  10. }
  11.  
  12. #footer {
  13.     background-color:black;
  14.     color:white;
  15.     clear:both;
  16.     text-align:center;
  17.    padding:30px;         
  18. }
  19. </style>
  20. </head>
  21.  
  22. <body>
  23.  
  24. <div id="header">
  25. <font size="5"><h1>Weather Search</h1></font>
  26. </div>
  27.  
  28.     <form ><p><center>
  29.                 Enter your location: <input id = "uid" type = "text" name="location">
  30.                 <br>
  31.                 <input type = "button" value = "Enter" id = "b">
  32.       </form></p></center>
  33.      
  34.     <div id='infoSummary'>  
  35.     </div>
  36.    
  37.     <div id='infoDetails'>
  38.    
  39.     </div>
  40.  
  41.     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
  42.     <script>      
  43.         serviceLocation = "http://api.worldweatheronline.com/free/v2/weather.ashx";
  44.         key = "882e641582ec4932ba6ff5c9dad5e";
  45.        
  46.  
  47.         myQuery = {};
  48.         myQuery.format = "json";
  49.         myQuery.num_of_days = "5";
  50.              
  51.  
  52.        
  53.         $("#b").click(function (){
  54.        
  55.            myQuery.q = $("#uid").val();
  56.            
  57.             req = serviceLocation + "?";
  58.             $.each(myQuery, function (k, v) {
  59.                req += k + '=' + v + '&';  
  60.             });  
  61.  
  62.             req += 'key' + '=' + key;
  63.        
  64.            // alert("The API call is" + req);
  65.  
  66.             $.getJSON(req, function (res){
  67.  
  68.                 var weatherIconUrl = res.data.current_condition[0].weatherIconUrl[0].value;              
  69.                 var observation_time = res.data.current_condition[0].observation_time;
  70.                 var temp_C = res.data.current_condition[0].temp_C;
  71.                 var cloudcover = res.data.current_condition[0].cloudcover;
  72.                 var visibility = res.data.current_condition[0].visibility;
  73.                 var windspeedMiles = res.data.current_condition[0].windspeedMiles;
  74.                 var FeelsLikeC = res.data.current_condition[0].FeelsLikeC;
  75.            
  76.            
  77.                 $('#infoSummary').html('<center><img src="'+ weatherIconUrl + '"height="150" width="150"></center>');            
  78.                 $('#infoDetails').html(
  79.                     "<center>At the time <b>" + observation_time + "</b>" +
  80.                            " the weather for " + myQuery.q + " was at <b>" + temp_C + " &deg;C </b>" +
  81.                            " with cloud cover of <b>" + cloudcover + "%</b>." +
  82.                            "<b><p>Other Stats</b> - <p>Visibility is currently at - <b>" + visibility +"%</p></b> <p>Wind Speeds of - <b>" + windspeedMiles + "MPH</b><p>Feels Like - <b>" + FeelsLikeC +"&deg;C</p></b></center>");            
  83.             });
  84.         });      
  85.     </script>
  86.    
  87. <p>
  88. <p>
  89. <p>
  90. <p>
  91. <p>
  92. <div id="footer">
  93. <font size="3">Paymon - M00435694 - CSD2550</font>
  94. </div>
  95.  
  96.    
  97. </body>
  98. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement