<?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/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">

<channel>
	<title>Werner Creixell &#187; PHP</title>
	<atom:link href="http://profesores.elo.utfsm.cl/~wcreixell/index.html/?feed=rss2&#038;tag=php" rel="self" type="application/rss+xml" />
	<link>http://profesores.elo.utfsm.cl/~wcreixell</link>
	<description>Personal web page</description>
	<lastBuildDate>Fri, 20 Mar 2026 13:06:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.6.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.0/cl/</creativeCommons:license>		<item>
		<title>Earthquakes in Google Maps</title>
		<link>http://profesores.elo.utfsm.cl/~wcreixell/?p=160</link>
		<comments>http://profesores.elo.utfsm.cl/~wcreixell/?p=160#comments</comments>
		<pubDate>Wed, 16 Jun 2010 15:10:43 +0000</pubDate>
		<dc:creator>Werner Creixell</dc:creator>
				<category><![CDATA[SeminarioII]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascrip]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://profesores.elo.utfsm.cl/~wcreixell/?p=160</guid>
		<description><![CDATA[In this example the Seminario II sutdents were asked to design a web page that display a Google map with earthquake information from the US Geological Survey USGS. Camilo Vera solution can be found here (gracias Camilo). Camilo&#8217;s php script is as follows: &#60;?php //header("Content-type= application/json"); $xml =simplexml_load_file("http://earthquakes.usgs.gov/earthquakes/catalogs/1day-M2.5.xml"); $i=0; //se recorren todos los nodos "entry" [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>In this example the Seminario II sutdents were asked to design a web page that display a <a href="http://maps.google.com">Google map</a> with earthquake information from the <a href="http://www.usgs.gov/">US Geological Survey USGS</a>.</p>
<p>Camilo Vera solution can be found <a href="http://profesores.elo.utfsm.cl/~wcreixell/camilo/">here</a> (gracias Camilo).</p>
<p>Camilo&#8217;s php script is as follows:</p>
<pre name="code" class="php">
&lt;?php
//header("Content-type= application/json");
$xml =simplexml_load_file("http://earthquakes.usgs.gov/earthquakes/catalogs/1day-M2.5.xml");
$i=0;
//se recorren todos los nodos "entry"
foreach($xml->entry as $node){
    //se recuperan los datos que tiene un namespace especificado por la siguiente url
    $geo = $node->children("http://www.georss.org/georss");
    $json[$i][0]=$geo->point;
    $json[$i][1]=$node->title;
    $i++;
}
print(json_encode($json));
?>
</pre>
<p>The javascript is as follows:</p>
<pre name="code" class="javascript">
function initialize() {
    myLatlng = new google.maps.LatLng(-33.04299, -71.586657);
    var myOptions = {
      zoom: 3,
      center: myLatlng,
      mapTypeId: google.maps.MapTypeId.TERRAIN
    }
    //se crea una instancia de un mapa de google
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    var request = crear_XmlHttpRequest();
    request.open("GET", "Conector.php", true);
    request.onreadystatechange = function() {
        if(request.readyState == 4 &#038;&#038; request.status == 200){
            var yw_json = request.responseText;
                      //dirty JSON evaluation
            var yw = eval('(' + yw_json + ')');
            var i;
            //se recorren el arreglo que contiene la informacion de las coordenadas y el nombre
            //del lugar donde ocurrio el terremoto
            for(i in yw){
                //la tercera dimension del arreglo es inutil, pero lamentablemente json_encode de php lo crea
                //se separan los dos puntos que determinan la coordenada
                coordenadas = yw[i][0][0].split(" ");
                //se guarda el nombre del lugar donde ocurrio el evento
                lugar = yw[i][1][0];
                //se crea el marcador en el mapa
                myLatlng = new google.maps.LatLng(coordenadas[0], coordenadas[1]);
                new google.maps.Marker({
                    position: myLatlng,
                    map: map,
                    title:lugar
                });
            }
        }
    }
    request.send(null);
  }

//Se define una funcion que retorne el objeto XMLHttpRequest dado que en la
//version 3 de la api de google se quito la clase GXmlHttp

function crear_XmlHttpRequest(){
    var httpRequest;
    if (window.XMLHttpRequest){
        //El explorador implementa la interfaz de forma nativa
	httpRequest = new XMLHttpRequest();
    }
    else if (window.ActiveXObject){
        //El explorador permite crear objetos ActiveX
	try {
            httpRequest = new ActiveXObject("MSXML2.XMLHTTP");
	} catch (e) {
            try {
                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    if (!httpRequest){
        alert("No ha sido posible crear una instancia de XMLHttpRequest");
    }
    return httpRequest;
}
</pre>
<p>The Html file is:</p>
<pre name="code" class="html">
&lt;html>
    &lt;head>
        &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        &lt;meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
        &lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">&lt;/script>
        &lt;script type="text/javascript" src="ajax_map.js">&lt;/script>
        &lt;title>&lt;/title>
    &lt;/head>
    &lt;body onload="initialize()">
        &lt;div id="map_canvas" style="width:100%; height:100%">&lt;/div>
        &lt;/body>
&lt;/html>
</pre>
<p>Alejandro Homes solution can be found <a href="http://profesores.elo.utfsm.cl/~wcreixell/alejandro/mapa.html">here</a> (gracias Alejandro). In this example the students used a php script as middle man to by pass the cross-domain restriction in web browsers.</p>
<p>The php script goes as follows:</p>
<pre name="code" class="php">
&lt;?php  

//First send the corresponding headers  

header("Content-type= application/json");  

 

//get the XML data from the URL  

$xml = simplexml_load_file("http://earthquake.usgs.gov/earthquakes/catalogs/1day-M2.5.xml");  



$count=0;

//traverse the SimpleXML object and store in a associative array  

foreach( $xml->entry as $entry ) 

{ 

	$aeo = $entry->children("http://www.georss.org/georss");

	$arr[$count] = array ('nombre'=>$entry->title,'fecha'=>$entry->updated,'geo_point'=>$aeo->point,'geo_elev'=>$aeo->elev);

	$count++;

}

  

//JSON enconde and print  

print(json_encode($arr));



?>
</pre>
<p>The html page is as follows:</p>
<pre name="code" class="html">
&lt;!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html xmlns="http://www.w3.org/1999/xhtml">
&lt;head>
	&lt;meta http-equiv="content-type" content="text/html; charset=utf-8"/>
	&lt;title>Google Maps JavaScript API Example&lt;/title>
	&lt;script src="http://maps.google.com/maps?file=api&#038;v=2&#038;key=ABQIAAAAw0DAzQTTbMAlKOPlgYZyaxT2yXp_ZAY8_ufC3CFXhHIE1NvwkxT4oLUvcIuwHQ71styNxZCnK2iqoQ"
		type="text/javascript">&lt;/script>
	&lt;script type="text/javascript">

	function reFresh() {
		location.reload(true)
	}


	function initialize() {
		if (GBrowserIsCompatible()) {

			function setMarker( punto, texto){

				var marker = new GMarker(punto, {draggable: false});

				GEvent.addListener(marker, "click", function(){
					// create the Google version of XMLHttpRequest object
					marker.openInfoWindowHtml(texto);
				});

				map.addOverlay(marker);
			}
			
			var map = new GMap2(document.getElementById("map_canvas"));
		
			var center = new GLatLng(-15,0);
		
			map.setCenter(center, 1);

			var request = GXmlHttp.create();
			request.open("GET", "usgs.php", true);
			request.onreadystatechange = function() 
			{
				if(request.readyState == 4 &#038;&#038; request.status == 200){
			
					var eq_json = request.responseText;
					var eq = eval('(' + eq_json + ')');
					
					var i;
					for(i in eq)
					{
						
						var lat_lng = eq[i].geo_point[0].split(" ");
						var titulo = eq[i].nombre[0].split(",");
						var magnitud = titulo[0].split(" ");
		
						var xhtml = "lugar = " + titulo[1] + ", " + titulo[2] + "&lt;br />";
						xhtml += "magnitud = " + magnitud[1] + "° Richter&lt;br />";
						xhtml += "fecha = " + eq[i].fecha[0] + "&lt;br />";
						xhtml += "elevación = " + eq[i].geo_elev[0]/1000 + " [Km]&lt;br />";
						xhtml += "posición = " + eq[i].geo_point[0] + "&lt;br />";
						
						var point = new GLatLng(lat_lng[0],lat_lng[1]);
						setMarker(point, xhtml);
					}
					//end for
				
				}
			}
			
			request.send(null);

		}
	window.setInterval("reFresh()",60000); //recarga la pag cada 1 minuto
	}​
	&lt;/script>
&lt;/head>
&lt;body onload="initialize()" onunload="GUnload()">
	&lt;div id="map_canvas" style="width: 700px; height:550px">&lt;/div>
&lt;/body>
&lt;/html>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://profesores.elo.utfsm.cl/~wcreixell/?feed=rss2&#038;p=160</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Yahoo Weather in Google Maps</title>
		<link>http://profesores.elo.utfsm.cl/~wcreixell/?p=70</link>
		<comments>http://profesores.elo.utfsm.cl/~wcreixell/?p=70#comments</comments>
		<pubDate>Wed, 12 May 2010 12:58:56 +0000</pubDate>
		<dc:creator>Werner Creixell</dc:creator>
				<category><![CDATA[SeminarioII]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[Yahoo! Weather]]></category>

		<guid isPermaLink="false">http://profesores.elo.utfsm.cl/~wcreixell/?p=70</guid>
		<description><![CDATA[This is a toy example that I used to challenge my students at seminario II. The idea is to display the Yahoo! Weather information in a google map, as showed in this page (click in the marker and the weather info for Valparaíso will appear). We first grab the information, by a php script, from [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>This is a toy example that I used to challenge my students at <a href="http://www.ramos.utfsm.cl/index.php?id=1172" target="_blank">seminario II</a>. The idea is to display the <a href="http://weather.yahoo.com/" target="_blank">Yahoo! Weather </a>information in a <a href="http://maps.google.com/" target="_blank">google map</a>, as showed in <a href="http://www.profesores.elo.utfsm.cl/~wcreixell/ejemplos/map3.html" target="_blank">this page</a> (click in the marker and the weather info for Valparaíso will appear).</p>
<p>We first grab the information, by a php script, from the Yahoo! Weather RSS feed. The feed is available from  the URL http://weather.yahooapis.com/forecastrss?w=349861&amp;u=c,  where w is the corresponding code for Valparaíso, and u is the temperature unit in Celsius. This php scrip can communicate with the client (the html page with the map) by  JSON or XML. The XML version is contributed by Jorge Flores a student in Seminario II (¡¡Gracias Jorge!!).<br />
The XML from the feed looks like</p>
<pre name="code" class="XML:nogutter">
&lt;?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
&lt;rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
&lt;channel>

&lt;title>Yahoo! Weather - Valparaiso, CI&lt;/title>
&lt;link>http://us.rd.yahoo.com/dailynews/rss/weather/Valparaiso__CI/*http://weather.yahoo.com/forecast/CIXX0026_c.html&lt;/link>
&lt;description>Yahoo! Weather for Valparaiso, CI&lt;/description>
&lt;language>en-us&lt;/language>
&lt;lastBuildDate>Tue, 11 May 2010 6:00 pm CLT&lt;/lastBuildDate>
&lt;ttl>60&lt;/ttl>
&lt;yweather:location city="Valparaiso" region=""   country="CI"/>

&lt;yweather:units temperature="C" distance="km" pressure="mb" speed="km/h"/>
&lt;yweather:wind chill="11"   direction="190"   speed="9.66" />
&lt;yweather:atmosphere humidity="88"  visibility="4.01"  pressure="982.05"  rising="0" />
&lt;yweather:astronomy sunrise="7:26 am"   sunset="5:58 pm"/>
&lt;image>
&lt;title>Yahoo! Weather&lt;/title>
&lt;width>142&lt;/width>
&lt;height>18&lt;/height>
&lt;link>http://weather.yahoo.com&lt;/link>
&lt;url>http://l.yimg.com/a/i/us/nws/th/main_142b.gif&lt;/url>
&lt;/image>
&lt;item>

&lt;title>Conditions for Valparaiso, CI at 6:00 pm CLT&lt;/title>
&lt;geo:lat>-32.78&lt;/geo:lat>
&lt;geo:long>-71.53&lt;/geo:long>
&lt;link>http://us.rd.yahoo.com/dailynews/rss/weather/Valparaiso__CI/*http://weather.yahoo.com/forecast/CIXX0026_c.html&lt;/link>
&lt;pubDate>Tue, 11 May 2010 6:00 pm CLT&lt;/pubDate>
&lt;yweather:condition  text="Fog"  code="20"  temp="11"  date="Tue, 11 May 2010 6:00 pm CLT" />
&lt;description>&lt;![CDATA[
&lt;img src="http://l.yimg.com/a/i/us/we/52/20.gif"/>&lt;br />
&lt;b>Current Conditions:&lt;/b>&lt;br />
Fog, 11 C&lt;BR />
&lt;BR />&lt;b>Forecast:&lt;/b>&lt;BR />
Tue - Cloudy. High: 20 Low: 9&lt;br />
Wed - Partly Cloudy. High: 20 Low: 9&lt;br />
&lt;br />
&lt;a href="http://us.rd.yahoo.com/dailynews/rss/weather/Valparaiso__CI/*http://weather.yahoo.com/forecast/CIXX0026_c.html">Full Forecast at Yahoo! Weather&lt;/a>&lt;BR/>&lt;BR/>
(provided by &lt;a href="http://www.weather.com" >The Weather Channel&lt;/a>)&lt;br/>
]]&gt;&lt;/description>
&lt;yweather:forecast day="Tue" date="11 May 2010" low="9" high="20" text="Cloudy" code="26" />
&lt;yweather:forecast day="Wed" date="12 May 2010" low="9" high="20" text="Partly Cloudy" code="30" />
&lt;guid isPermaLink="false">CIXX0026_2010_05_11_18_00_CLT&lt;/guid>
&lt;/item>

&lt;/channel>
&lt;/rss>&lt;!-- api4.weather.ac4.yahoo.com compressed/chunked Wed May 12 06:05:42 PDT 2010 -->
</pre>
<p>We can observe that there are two different name spaces, yweather and geo. We need just those names under yweather. In particular we use yweather:condition, this element holds the current weather information on its attributes. </p>
<h2>JSON version</h2>
<p>The php goes as follows</p>
<pre name="code" class="php">&lt;?php
//First send the corresponding headers
header("Content-type= application/json");
//get the XML data from the URL
$xml = simplexml_load_file("http://weather.yahooapis.com/forecastrss?w=349861&amp;u=c");
//obtaining the namespace for yweather
$yweather =$xml->channel->item->children("http://xml.weather.yahoo.com/ns/rss/1.0");

//traverse the SimpleXML object and store in a associative array
foreach( $yweather->condition->attributes() as $k=>$attr)
     $condition[$k] = $attr;

//JSON enconde and print
print(json_encode($condition));
?&gt;
</pre>
<p>On the html page we receive the information in the JSON format and passed to the openInfoWindowHtml() method of google maps.</p>
<pre name="code" class="html">
&lt;!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html xmlns="http://www.w3.org/1999/xhtml">
  &lt;head>
    &lt;meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    &lt;title>Google Maps JavaScript API Example&lt;/title>
    &lt;script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAADI36Gd6uqs4OgrvF2FK3TRS3WQwwXk35PFrPy_oZlvjggyWGmxSJfJA31Kd06D9lQVQJpKvCzFGD3g"
            type="text/javascript">&lt;/script>
    &lt;script type="text/javascript">

function initialize() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map_canvas"));
   //a marker placed in our university 
    var center = new GLatLng(-33.033276,-71.594682);
    map.setCenter(center, 15);

    var marker = new GMarker(center, {draggable: true});

   		
		//Adding Yahoo! Weather
		
		GEvent.addListener(marker, "click", 
		function(){
        // create the Google version of XMLHttpRequest object
			var request = GXmlHttp.create();
			request.open("GET", "weather2.php", true);
			
			request.onreadystatechange = function() {
				
				if(request.readyState == 4 &#038;&#038; request.status == 200){
					
					var xhtml = "&lt;b>Yahoo! Weather&lt;/b>";
					xhtml += "&lt;br />";
					
					var yw_json = request.responseText;
                      //dirty JSON evaluation
					var yw = eval('(' + yw_json + ')');
					
					xhtml = xhtml + "temperatura =" + yw.temp[0] +" ºC &lt;br />";
					xhtml += yw.date[0];
					marker.openInfoWindowHtml(xhtml);
				}
			}
			//send the request
			request.send(null);
		});
		
		
    map.addOverlay(marker);

  }
}​
   &lt;/script>
  &lt;/head>
  &lt;body onload="initialize()" onunload="GUnload()">
    &lt;div id="map_canvas" style="width: 800px; height: 500px">&lt;/div>
  &lt;/body>
&lt;/html>
</pre>
<h2>XML version</h2>
<p>The php goes as follows</p>
<pre name="code" class="php">
&lt;?php
//First the corresponding XML headers
header("Content-type: text/xml");
//Jorge sends the location by GET
$w = $_GET["w"];
$url =  "http://weather.yahooapis.com/forecastrss?w=" . $w . "&#038;u=c";
if($xml = file_get_contents($url)){

	$obj = simplexml_load_string($xml);
	$item = $obj->channel->item;
//formatting the XML output
	print("&lt;weather>");
	print("&lt;title>" . $item->title . "&lt;/title>");
//getting the namespace
	$child = $item->children("http://xml.weather.yahoo.com/ns/rss/1.0");
	$att = $child->condition->attributes();
	print("&lt;temp>" . $att->text . " " . $att->temp . "ºC&lt;/temp>");
	print("&lt;/weather>");
}
?>
</pre>
<p>Jorge&#8217;s html file goes like this</p>
<pre name="code" class="html">
&lt;html>
	&lt;head>
	&lt;script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAzsVe8ueaD3_5_TOp88LiKRTmhXfEnveThyX0qgmXnRV_0BrCwBTi62Ue7Uv5MEgulw1nxTmAQ2jihA" type="text/javascript">&lt;/script>
		&lt;script type="text/javascript">
			function load(){
				var map = new GMap2(document.getElementById("map"));

				var point = new GLatLng(-33.05,-71.6);
				var w = 349861;

				map.setCenter(point,13);

				var marker = new GMarker(point);
				map.addOverlay(marker);

				GEvent.addListener(marker,"click",function(){
						var request = GXmlHttp.create();
						request.open("GET","getWeather.php?w=" + w,true);
						request.onreadystatechange = function(){
							if(request.readyState == 4 &#038; request.status == 200){

								var weather = request.responseXML.getElementsByTagName("weather")[0];
								var title = weather.getElementsByTagName("title")[0].firstChild.nodeValue;
								var temp = weather.getElementsByTagName("temp")[0].firstChild.nodeValue;

								var xhtml = "&lt;b>" + title + ":&lt;/b> &lt;br />";

								xhtml += "&lt;div align=center>&lt;h2>" + temp + "&lt;/h2>&lt;/div>";

								map.openInfoWindowHtml(point,xhtml);
							}
						}
						request.send(null);
					}
					);
			}
		&lt;/script>
	&lt;/head>
	&lt;body onload="load();">
		&lt;div id="map" style="height:100%; width:100%"> &lt;/div>
	&lt;/body>

&lt;/html>
</pre>
<p>The main differences with the JSON version are in the request.onreadystatechange handler, where there is a little more code to traverse the XML data. You can check the result <a href="http://www.profesores.elo.utfsm.cl/~wcreixell/ejemplos/weathermap.html">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://profesores.elo.utfsm.cl/~wcreixell/?feed=rss2&#038;p=70</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
