Created
August 20, 2012 16:07
-
-
Save cam-gists/3405399 to your computer and use it in GitHub Desktop.
PHP: Google Weather API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function GetWeather($state,$country,$langauge,$waetherIcons){ | |
// auf der Basis von http://www.web-spirit.de/webdesign-tutorial/9/Wetter-auf-eigener-Website-mit-Google-Weather-API | |
$api = simplexml_load_string(utf8_encode(file_get_contents("http://www.google.com/ig/api?weather=".$state."-".$country."&hl=".$langauge))); | |
// $trans = array("ä" => "ä", "Ä" => "Ä", "ü" => "ü", "Ü" => "Ü", "ö" => "ö", "Ö" => "Ö", "ß" => "ß"); | |
$trans = array("ü" => "ü", "ö" => "ö", "ä" => "ä", "ß" => "ß"); | |
$weather = array(); | |
$i = 1; | |
foreach($api->weather->forecast_conditions as $GoogleWeather){ | |
$waetherIcons = $GoogleIcons = "/ig/images/weather/"; | |
$weather[$i]['zustand'] = strtr(strtolower($GoogleWeather->condition->attributes()->data), $trans); | |
$weather[$i]['tiefsttemperatur'] = $GoogleWeather->low->attributes()->data; | |
$weather[$i]['hoechsttemperatur'] = $GoogleWeather->high->attributes()->data; | |
$weather[$i]['icon'] = str_replace($GoogleIcons, $waetherIcons, $GoogleWeather->icon->attributes()->data); | |
$i++; | |
} | |
return $weather; | |
} | |
GetWeather('ca', 'usa', 'en', 'true'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment