Advertisement
Guest User

whole weather code

a guest
Apr 24th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 7.86 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <ul>
  4. <li><a href = 'homepage.php'>Home</a></li>
  5. <li><a href = 'csd 2550 html website contact us.php'>Contact Us</a></li>
  6. <li><a href = 'website about us.php'>About Us</a></li>
  7. </ul>
  8.  
  9.  
  10. <link rel="stylesheet" type="text/css" href="styleupload.css">
  11. <head>
  12. <body background = "aurora-borealis-background.jpg"/>
  13.   <title>Weather Forecast Center</title>
  14.  
  15.   <h1> Weather Details </h1>
  16.  
  17. </head>
  18. <br>
  19. <br>
  20. <body>
  21.     <form>
  22.         <p><b><font color = "blue">Type in City or Postcode: </p></b></font> <input type="text" name="GetCity" id="city">
  23.         <br>
  24.         <br>
  25.        <input type="button" value="Submit" id="findcity">  
  26.     </form>
  27.    
  28.     <div id='infoSummary'>
  29.        <!-- Info will come here -->      
  30.     </div>
  31.    
  32.     <div id='infoDetails'>
  33.        <!-- Info will come here -->      
  34.     </div>
  35.  
  36.   <head>
  37.     <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
  38.     <meta charset="utf-8">
  39.     <style>
  40.       html, body, #map-canvas {
  41.         height: 90%;
  42.         margin: 0px;
  43.         padding: 0px
  44.       }
  45.       .controls {
  46.         margin-top: 16px;
  47.         border: 1px solid transparent;
  48.         border-radius: 2px 0 0 2px;
  49.         box-sizing: border-box;
  50.         -moz-box-sizing: border-box;
  51.         height: 32px;
  52.         outline: none;
  53.         box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  54.       }
  55.  
  56.       #pac-input {
  57.         background-color: #fff;
  58.         font-family: Verdana;
  59.         font-size: 15px;
  60.         font-weight: 300;
  61.         margin-left: 12px;
  62.         padding: 0 11px 0 13px;
  63.         text-overflow: ellipsis;
  64.         width: 400px;
  65.       }
  66.  
  67.       #pac-input:focus {
  68.         border-color: #4d90fe;
  69.       }
  70.  
  71.       .pac-container {
  72.         font-family: Verdana;
  73.       }
  74.  
  75.       #type-selector {
  76.         color: #fff;
  77.         background-color: #4d90fe;
  78.         padding: 5px 11px 0px 11px;
  79.       }
  80.  
  81.       #type-selector label {
  82.         font-family: Verdana;
  83.         font-size: 13px;
  84.         font-weight: 300;
  85.       }
  86.  
  87.     </style>
  88.     <title>Places search box</title>
  89.     <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=places"></script>
  90.     <script>
  91. // This example adds a search box to a map, using the Google Place Autocomplete
  92. // feature. People can enter geographical searches. The search box will return a
  93. // pick list containing a mix of places and predicted search terms.
  94.  
  95. function initialize() {
  96.  
  97.   var markers = [];
  98.   var map = new google.maps.Map(document.getElementById('map-canvas'), {
  99.     mapTypeId: google.maps.MapTypeId.ROADMAP
  100.   });
  101.  
  102.   var defaultBounds = new google.maps.LatLngBounds(
  103.       new google.maps.LatLng(-33.8902, 151.1759),
  104.       new google.maps.LatLng(-33.8474, 151.2631));
  105.   map.fitBounds(defaultBounds);
  106.  
  107.   // Create the search box and link it to the UI element.
  108.   var input = /** @type {HTMLInputElement} */(
  109.       document.getElementById('pac-input'));
  110.   map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
  111.  
  112.   var searchBox = new google.maps.places.SearchBox(
  113.     /** @type {HTMLInputElement} */(input));
  114.  
  115.   // [START region_getplaces]
  116.   // Listen for the event fired when the user selects an item from the
  117.   // pick list. Retrieve the matching places for that item.
  118.   google.maps.event.addListener(searchBox, 'places_changed', function() {
  119.     var places = searchBox.getPlaces();
  120.  
  121.     if (places.length == 0) {
  122.       return;
  123.     }
  124.     for (var i = 0, marker; marker = markers[i]; i++) {
  125.       marker.setMap(null);
  126.     }
  127.  
  128.     // For each place, get the icon, place name, and location.
  129.     markers = [];
  130.     var bounds = new google.maps.LatLngBounds();
  131.     for (var i = 0, place; place = places[i]; i++) {
  132.       var image = {
  133.         url: place.icon,
  134.         size: new google.maps.Size(71, 71),
  135.         origin: new google.maps.Point(0, 0),
  136.         anchor: new google.maps.Point(17, 34),
  137.         scaledSize: new google.maps.Size(25, 25)
  138.       };
  139.  
  140.       // Create a marker for each place.
  141.       var marker = new google.maps.Marker({
  142.         map: map,
  143.         icon: image,
  144.         title: place.name,
  145.         position: place.geometry.location
  146.      
  147.       });
  148.  
  149.       markers.push(marker);
  150.  
  151.       bounds.extend(place.geometry.location);
  152.     }
  153.  
  154.    
  155.    
  156.     map.fitBounds(bounds);
  157.   });
  158.   // [END region_getplaces]
  159.  
  160.   // Bias the SearchBox results towards places that are within the bounds of the
  161.   // current map's viewport.
  162.   google.maps.event.addListener(map, 'bounds_changed', function() {
  163.     var bounds = map.getBounds();
  164.     searchBox.setBounds(bounds);
  165.   });
  166. }
  167.  
  168.  
  169.  
  170. google.maps.event.addDomListener(window, 'load', initialize);
  171.  
  172.     </script>
  173.     <style>
  174.       #target {
  175.         width: 345px;
  176.       }
  177.     </style>
  178.   </head>
  179.   <body>
  180.     <input id="pac-input" class="controls" type="text" placeholder="Search Box">
  181.     <div id="map-canvas"></div>
  182. </body>
  183.  
  184.  
  185.  
  186.  
  187.     <!-- In your application, you may want to put the javascript code in a separate file -->
  188.     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
  189.     <script>      
  190.         serviceLocation = "http://api.worldweatheronline.com/free/v2/weather.ashx";
  191.         key = "dcf7208c86e37f2fa995d28084a03";
  192.        
  193.         //Bulid the components of the request
  194.         //(currently I chose some fixed data; but it could be taken from the user via a form)
  195.         myQuery = {};
  196.         myQuery.format = "json";
  197.         //myQuery.q = "London";
  198.         myQuery.num_of_days = "10";  
  199.        
  200.         $("#findcity").click(function () {
  201.             //The next will be executed when the button is clicked.
  202.           myQuery.q = document.getElementById("city").value;  
  203.             //Build the request to the service: service URL + query string
  204.             req = serviceLocation + "?";
  205.             $.each(myQuery, function (k, v) {
  206.             req += k + '=' + v + '&';  
  207.             });
  208.            
  209.             //For most APIs, when making calls you will need to add your key to the query string
  210.             //(the one you receive after registering to the service)
  211.             req += 'key' + '=' + key;
  212.            
  213.            
  214.             //alert(myQuery.q);
  215.            
  216.             //The getJson function takes two arguments:
  217.                 //(1) the http request to the service
  218.                 //(2) a function showing what to do with the result
  219.             //(see http://www.w3schools.com/jquery/ajax_getjson.asp)
  220.             $.getJSON(req, function (res){
  221.                 //Below we access the data from the JSON response, available as
  222.                 //a javascript object (see http://www.w3schools.com/jquery/ajax_getjson.asp).  
  223.                 //(The structure of the response is shown in the particlar API documentation,
  224.                 //in this case http://www.worldweatheronline.com/api/docs/)
  225.                 var weatherIconUrl = res.data.current_condition[0].weatherIconUrl[0].value;              
  226.                 var observation_time = res.data.current_condition[0].observation_time;
  227.                 var temp_C = res.data.current_condition[0].temp_C;
  228.                 var cloudcover = res.data.current_condition[0].cloudcover;
  229.                
  230.                 //Finally, we can put this data on the page, for example by accessing
  231.                 //elements by ID and altering their html content
  232.                 //(see http://www.w3schools.com/jquery/jquery_dom_set.asp)            
  233.                 $('#infoSummary').html('<img src="' + weatherIconUrl + '" height="342" width="342">');            
  234.                 $('#infoDetails').html(
  235.                     "At the time <b>" + observation_time + "</b>" +
  236.                            " the " + myQuery.q + " temperature was <b>" + temp_C + " &deg;C </b>" +
  237.                            " with cloud cover of <b>" + cloudcover + "%</b>.");            
  238.             });
  239.         });    
  240.     </script>
  241.    
  242. </body>
  243. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement