davidjmorin

Weather Script

Jul 20th, 2012
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.32 KB | None | 0 0
  1. <head>
  2.     <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
  3.    
  4. </head>
  5. <!--[if IE]>
  6. This page does not support Internet Explorer.  Please download <a href="http://google.com/chrome">Chrome</a> or<a href="http://mozilla.org"> Firefox</a> for your system.
  7. <![endif]-->
  8. <script src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
  9. <script src=geo.js></script>
  10. <script>
  11.     function onPositionUpdate(position)
  12.     {
  13.         var lat = position.coords.latitude;
  14.         var lng = position.coords.longitude;
  15.         // alert("Current position: " + lat + " " + lng);
  16.         document.getElementById("coord").value = ("" + lat + "," + lng);
  17.        
  18.        
  19.        
  20.     }
  21.    
  22.     if(navigator.geolocation)
  23.     navigator.geolocation.getCurrentPosition(onPositionUpdate);
  24.     else
  25.     alert("navigator.geolocation is not available");
  26.    
  27. </script>
  28.  
  29.  
  30. <form method="GET" action="test.php">
  31.     <input id="coord" name="coord" value="">
  32.     <input type="submit" value="Enter Location">
  33. </form>
  34. <?php
  35.     $weather_loc = $_GET["coord"];
  36.     echo $coord;
  37.    
  38.     $json_string2 =   file_get_contents("http://api.wunderground.com/api/YOURAPI/geolookup/conditions/forecast/q/$weather_loc.json");
  39.     $json_string =    file_get_contents("http://api.wunderground.com/api/YOURAPI/geolookup/conditions/forecast/q/$weather_loc.json");
  40.     $current_parse = json_decode($json_string2);
  41.     $parsed_json = json_decode($json_string, true);
  42.     $current = $current_parse->{'current_observation'}->{'temp_f'};
  43.     $parsed = $parsed_json['forecast']['txt_forecast']['forecastday'];
  44.     $loc = $parsed_json['location']['city'];
  45.     $state = $parsed_json['location']['state'];
  46.    
  47.     //pr($parsed_json);
  48.     if (empty($weather_loc)) {
  49.     echo 'No location has been set.  Please hit the button above';
  50. }
  51.  
  52. else {
  53.    
  54.     echo 'Weather forecast for: ',$loc , ',' ,$state;
  55.     echo '<center>Currently:  <b><font color="red">' . $current . 'F</center>';
  56.    
  57.     foreach($parsed as $key => $value)
  58.     {
  59.         echo '<table border="1" width="100%">';
  60.         echo '<tr>';
  61.         echo '<th><b>' . $value['title'] . '</th></font>';
  62.         echo '</tr>';
  63.         echo '<tr>';
  64.         echo '<td width="50%">' .$value['fcttext'] . '</td></font>';
  65.         echo '<td width="10%"><center><img src=' . $value['icon_url'] . '></td>';
  66.         echo '</tr></table>';
  67.     }  
  68.     echo '<div id="radar">';
  69.     echo '<td>';
  70.     //echo include ('./dom/yt.php');
  71.     echo '</td>';
  72.     echo '</div>';
  73.     }
  74. ?>
Advertisement
Add Comment
Please, Sign In to add comment