<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Spartan Code - Blog &#187; weather</title>
	<atom:link href="http://www.spartan-code.com/blog/tag/weather/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.spartan-code.com/blog</link>
	<description>web development</description>
	<lastBuildDate>Fri, 04 Nov 2011 19:43:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
	<!-- google_ad_section_end --><!-- google_ad_section_start(weight=ignore) -->	<item>
		<title>Acceder a Google Weather en PHP</title>
		<link>http://www.spartan-code.com/blog/google/acceder-a-google-weather-en-php/</link>
		<comments>http://www.spartan-code.com/blog/google/acceder-a-google-weather-en-php/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 12:24:08 +0000</pubDate>
		<dc:creator>Pirata21</dc:creator>
				<category><![CDATA[google]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[weather]]></category>

		<guid isPermaLink="false">http://www.spartan-code.com/blog/index.php/acceder-a-google-weather-en-php/</guid>
		<description><![CDATA[Interesante clase para acceder de un modo sencillo al servicio metereológico de Google.Ejemplo: &#60;?php class GoogleWeatherAPI { private $city_code = ''; private $city = ''; private $domain = 'www.google.com'; private $prefix_images = ''; private $current_conditions = array(); private $forecast_conditions = array(); private $is_found = true; /** * Class constructor * @param $city_code is the label [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-family: arial; font-size: 13px; line-height: normal; border-collapse: collapse" class="Apple-style-span">Interesante clase para acceder de un modo sencillo al servicio metereológico de Google.Ejemplo: </span>
<p style="width: 675px; overflow-x: auto; overflow-y: auto">
<pre style="font-size: 11px" name="code">&lt;?php class GoogleWeatherAPI {</pre>
<pre style="font-size: 11px" name="code">private $city_code = '';</pre>
<pre style="font-size: 11px" name="code">private $city = '';</pre>
<pre style="font-size: 11px" name="code">private $domain = 'www.google.com';</pre>
<pre style="font-size: 11px" name="code">private $prefix_images = '';</pre>
<pre style="font-size: 11px" name="code">private $current_conditions = array();</pre>
<pre style="font-size: 11px" name="code">private $forecast_conditions = array();</pre>
<pre style="font-size: 11px" name="code">private $is_found = true;</pre>
<pre style="font-size: 11px" name="code"></pre>
<pre style="font-size: 11px" name="code">/** 	* Class constructor</pre>
<pre style="font-size: 11px" name="code">* @param $city_code is the label of the city</pre>
<pre style="font-size: 11px" name="code">* @param $lang the lang of the return weather labels</pre>
<pre style="font-size: 11px" name="code">* @return ... 	*/</pre>
<pre style="font-size: 11px" name="code">function __construct ($city_code,$lang='fr')</pre>
<pre style="font-size: 11px" name="code">{</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>$this-&gt;city_code = $city_code;</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>$this-&gt;prefix_images = 'http://'.$this-&gt;domain;</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>$this-&gt;url = 'http://'.$this-&gt;domain.'/ig/api?weather='.urlencode($this-&gt;city_code).'&amp;hl='.$lang;</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>$content = utf8_encode(file_get_contents($this-&gt;url));</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>$xml = simplexml_load_string($content);</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>if(!isset($xml-&gt;weather-&gt;problem_cause)) {</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">		</span>$xml = simplexml_load_string($content);</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">		</span>$this-&gt;city = (string)$xml-&gt;weather-&gt;forecast_information-&gt;city-&gt;attributes()-&gt;data;</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">		</span>$this-&gt;current_conditions['condition'] = (string)$xml-&gt;weather-&gt;current_conditions-&gt;condition-&gt;attributes()-&gt;data;</pre>
<pre style="font-size: 11px" name="code">	<span class="Apple-tab-span" style="white-space: pre">	</span>$this-&gt;current_conditions['temp_f'] = (string)$xml-&gt;weather-&gt;current_conditions-&gt;temp_f-&gt;attributes()-&gt;data;</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">		</span>$this-&gt;current_conditions['temp_c'] = (string)$xml-&gt;weather-&gt;current_conditions-&gt;temp_c-&gt;attributes()-&gt;data;</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">		</span>$this-&gt;current_conditions['humidity'] = (string)$xml-&gt;weather-&gt;current_conditions-&gt;humidity-&gt;attributes()-&gt;data;</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">		</span>$this-&gt;current_conditions['icon'] = $this-&gt;prefix_images.(string)$xml-&gt;weather-&gt;current_conditions-&gt;icon-&gt;attributes()-&gt;data;</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">		</span>$this-&gt;current_conditions['wind_condition'] = (string)$xml-&gt;weather-&gt;current_conditions-&gt;wind_condition-&gt;attributes()-&gt;data;</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">		</span>foreach($xml-&gt;weather-&gt;forecast_conditions as $this-&gt;forecast_conditions_value) {</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">			</span>$this-&gt;forecast_conditions_temp = array();</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">			</span>$this-&gt;forecast_conditions_temp['day_of_week'] = (string)$this-&gt;forecast_conditions_value-&gt;day_of_week-&gt;attributes()-&gt;data;</pre>
<pre style="font-size: 11px" name="code"> 		<span class="Apple-tab-span" style="white-space: pre">	</span>$this-&gt;forecast_conditions_temp['low'] = (string)$this-&gt;forecast_conditions_value-&gt;low-&gt;attributes()-&gt;data;</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">			</span>$this-&gt;forecast_conditions_temp['high'] = (string)$this-&gt;forecast_conditions_value-&gt;high-&gt;attributes()-&gt;data;</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">			</span>$this-&gt;forecast_conditions_temp['icon'] = $this-&gt;prefix_images.(string)$this-&gt;forecast_conditions_value-&gt;icon-&gt;attributes()-&gt;data;</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">			</span>$this-&gt;forecast_conditions_temp['condition'] = (string)$this-&gt;forecast_conditions_value-&gt;condition-&gt;attributes()-&gt;data;</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">			</span>$this-&gt;forecast_conditions []= $this-&gt;forecast_conditions_temp;</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">		</span>}</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>}</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>else {</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">		</span>$this-&gt;is_found = false;</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>}</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>}</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>function getCity() {</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">		</span>return $this-&gt;city;</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>}</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>function getCurrent() {</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">		</span>return $this-&gt;current_conditions;</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>}</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>function getForecast() {</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">		</span>return $this-&gt;forecast_conditions;</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>}</pre>
<pre style="font-size: 11px" name="code"></pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>function isFound() {</pre>
<pre style="font-size: 11px" name="code"> 		return $this-&gt;is_found;</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="whit
e-space: pre">	</span>}</pre>
<pre style="font-size: 11px" name="code">}</pre>
<pre style="font-size: 11px" name="code"> $gweather = new GoogleWeatherAPI('valencia','es');</pre>
<pre style="font-size: 11px" name="code">if($gweather-&gt;isFound()) {</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>echo '&lt;pre&gt;'; print_r($gweather-&gt;getCity());</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>echo '&lt;/pre&gt;';</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>echo '&lt;pre&gt;';</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>print_r($gweather-&gt;getCurrent());</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>echo '&lt;/pre&gt;';</pre>
<pre style="font-size: 11px" name="code"><span class="Apple-tab-span" style="white-space: pre">	</span>echo '&lt;pre&gt;';</pre>
<pre style="font-size: 11px" name="code">print_r($gweather-&gt;getForecast()); echo '&lt;/pre&gt;';</pre>
<pre style="font-size: 11px" name="code">}</pre>
<pre style="font-size: 11px" name="code">?&gt;</pre>
<pre style="font-size: 11px" name="code"></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.spartan-code.com/blog/google/acceder-a-google-weather-en-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	<!-- google_ad_section_end --><!-- google_ad_section_start(weight=ignore) --></channel>
</rss>

