Advertisement
Guest User

Untitled

a guest
Dec 5th, 2011
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. <?php
  2. /** fetches weather data by given coordinates and returns xml **/
  3.  
  4. if (isset($_GET['la']) AND isset($_GET['lo'])) {
  5.     google_weather_api_coordinates($_GET['la'], $_GET['lo'], $_GET['lang']);
  6. } else if (isset($_GET['city'])) {
  7.     google_weather_api_city($_GET['city'], $_GET['lang']);
  8. }
  9.    
  10. function google_weather_api_coordinates($latitude, $longitude, $language) {
  11.     header("Content-type: text/xml; charset=utf-8");
  12.    
  13.     $la = $latitude*10000000;
  14.     $lo = $longitude*10000000;
  15.     $la = substr($la.'', 0, 8);
  16.     $lo = substr($lo.'', 0, 8);
  17.     $language = substr($language, 0, 2);
  18.    
  19.     $ch = curl_init();
  20.     curl_setopt($ch, CURLOPT_URL, "http://www.google.com/ig/api?weather=,,,".$la.",".$lo."&hl=".$language);
  21.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  22.     $xmlContents = utf8_encode(curl_exec($ch));
  23.     curl_close($ch);
  24.    
  25.     echo $xmlContents;
  26.    
  27. }
  28.  
  29. function google_weather_api_city($city, $language) {
  30.     header("Content-type: text/xml; charset=utf-8");
  31.    
  32.     $city = urlencode($city);
  33.     $language = substr($language, 0, 2);
  34.    
  35.     $ch = curl_init();
  36.     curl_setopt($ch, CURLOPT_URL, "http://www.google.com/ig/api?weather=".$city."&hl=".$language);
  37.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  38.     $xmlContents = utf8_encode(curl_exec($ch));
  39.     curl_close($ch);
  40.    
  41.     echo $xmlContents;
  42.    
  43. }
  44.  
  45.  
  46. ?>
  47.  
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement