/ Published in: PHP
URL: http://blog.programmableweb.com/2010/02/08/googles-secret-weather-api/
Use param hl for localization
Expand |
Embed | Plain Text
/* * @param string $destination Example: Paris * */ function get_weather($destination) { $ch = curl_init(); $result = ''; curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/ig/api?weather='.$destination.'&hl=sk'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // RETURN THE CONTENTS OF THE CALL if ($res === false) { echo 'Nepodarilo sa zistiÅ¥ poÄ�asie.'; return false; } $xml = new SimplexmlElement($res); { foreach($xml->weather as $item) { /* $current = $item->current_conditions; $result = '<div class="weather_icon">Dnes <br />'. '<img src="http://www.google.com/' .$current->icon['data'] . '"/><br />'. $current->temp_c['data'].'°C</div>'; */ foreach($item->forecast_conditions as $new) { <img src="http://www.google.com/' .$new->icon['data'] . '"/><br />'. $new->low['data'].'-'.$new->high['data'].'°C</div>'; } } } return $result; }
You need to login to post a comment.
