Home » Featured, Programmings

Google Weather API

Author : Izul Cyber Cafe 26 June 2010 192 views No Comment

Hari ini ingin sekali menulis, dan mumpung ada kesempatan untuk menulis akhir nya muncul lah artikel ini :)

Kali ini saya akan membahas Google API tepat nya Google Weather API, yaitu Google API yang di gunakan untuk menampilkan keadaan cuaca disuatu tempat.

yeah mari mulai.

1. Buat File PHP, Beri nama cuaca.php.

2. Tuliskan script berikut.

<?php function getWeather() {
 
	$requestAddress = "http://www.google.com/ig/api?weather=jakarta&hl=id";
	$xml_str = file_get_contents($requestAddress,0);
	// Parses XML
	$xml = new SimplexmlElement($xml_str);
	// Loops XML
	$count = 0;
	echo <<< END
 
END;
//echo $xml->forecast_conditions[0]->city['data'];
//var_dump($xml);
echo '<div id="weather">';
	foreach($xml->weather as $item) {
 
		foreach($item->forecast_conditions as $new) {
		echo '<div class="weatherIcon">';
			echo '<img src="http://www.google.com/' .$new->icon['data'] . '"/><br/>';
			echo $new->day_of_week['data'];
			echo '</div>';
 
		}
	}
  echo '</div>';
  }
 
  getWeather();?>

yang perlu anda perhatikan yaitu pada bagian

$requestAddress = "http://www.google.com/ig/api?weather=jakarta&hl=id";

disitu saya mencoba untuk melihat cuaca JAKARTA dengan bahasa Indonesia untuk hari nya.
3. Jalankan file cuaca.php

4. Selesai..

Sekian tutorial singkat nya.

Demo

———————————
Referensi

http://www.google.com/ig/api?weather=New%20York

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.