<?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>reweb Labs &#187; Google Maps</title>
	<atom:link href="http://labs.reweb.com.ar/tag/google-maps/feed" rel="self" type="application/rss+xml" />
	<link>http://labs.reweb.com.ar</link>
	<description>Donde la magia sucede</description>
	<lastBuildDate>Thu, 25 Feb 2010 11:37:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MySQL result to KML file output &#8211; PHP</title>
		<link>http://labs.reweb.com.ar/37-mysql-result-to-kml-file-output-php</link>
		<comments>http://labs.reweb.com.ar/37-mysql-result-to-kml-file-output-php#comments</comments>
		<pubDate>Sun, 16 Aug 2009 17:42:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[KML]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://labs.reweb.com.ar/?p=37</guid>
		<description><![CDATA[Description
This package offers a function called mysqlAKML (resource $mysqlResult, string $documentName=&#8217;kml&#8217;, string $itemName=&#8217;Placemark&#8217;); used to output a Mysql result with the following fields:
name: TEXTVALUE &#8211; The Name of the marker
description: TEXTVALUE &#8211; The description shown in the info window when marker clicked
coordinates: TEXTVALUE as (DOUBLE + &#8216;, &#8216; + DOUBLE) like &#8220;longitude, latitude&#8221;
Usage
So an easy [...]]]></description>
			<content:encoded><![CDATA[<h2>Description</h2>
<p>This package offers a function called <strong>mysqlAKML</strong> (resource $mysqlResult, string $documentName=&#8217;kml&#8217;, string $itemName=&#8217;Placemark&#8217;); used to output a Mysql result with the following fields:</p>
<p><em>name</em>: TEXTVALUE &#8211; The Name of the marker<br />
<em>description</em>: TEXTVALUE &#8211; The description shown in the info window when marker clicked<br />
<em>coordinates</em>: TEXTVALUE as (DOUBLE + &#8216;, &#8216; + DOUBLE) like &#8220;longitude, latitude&#8221;</p>
<h2>Usage</h2>
<p>So an easy way to obtain the KML would be:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$qString</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT
markerName AS name,
myText AS description,
CONCAT (latitude, ', ', longitude) AS coordinates
FROM myTable&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$qString</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$myKML</span> <span style="color: #339933;">=</span> mysql_KML<span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>A complete example:</p>
<h3>File getPoints.php</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #b1b100;">require</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'connetion.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mysqlAKML-1.1.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// obtain the MySQL resutl</span>
<span style="color: #000088;">$makers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$queryString</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// KML Content-Type (application/vnd.google-earth.kml+xml)</span>
<span style="color: #990000;">header</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: application/vnd.google-earth.kml+xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Disposition: attachment; filename=&quot;markers.kml&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Display the file content</span>
<span style="color: #b1b100;">echo</span> mysql_KML<span style="color: #009900;">&#40;</span><span style="color: #000088;">$markers</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Then, if we want to load this KML in a Google Map with the Google Maps API with JavaScript, we shoul add the following code to our load() function:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// JavaScript</span>
<span style="color: #003366; font-weight: bold;">function</span> load<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
...
...
<span style="color: #006600; font-style: italic;">// add Markers fetched from the DB to the map</span>
<span style="color: #003366; font-weight: bold;">var</span> geoXml <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> GGeoXml<span style="color: #009900;">&#40;</span>PATH_TO_FILE <span style="color: #339933;">+</span> <span style="color: #3366CC;">'getPoints.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
map.<span style="color: #660066;">addOverlay</span><span style="color: #009900;">&#40;</span>geoXml<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
...
...
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Thats all! Feel free to modify the file but remember to leave my name! See the working example in the link below</p>
<h2>Working Example</h2>
<p><a href='http://www.cordobalquila.com.ar/inmobiliarias'>Example</a></p>
<h2>Downloads</h2>
<p><a href="http://labs.reweb.com.ar/wp-content/uploads/2009/08/mysqlakml-11.rar">Download Package File (mysqlAKML-1.1.php)</a></p>
<h2>Usefull Links</h2>
<p><a href='http://code.google.com/intl/es-AR/apis/maps/documentation/reference.html#GGeoXml'>GGeoXML in Google Maps API Reference</a></p>
]]></content:encoded>
			<wfw:commentRss>http://labs.reweb.com.ar/37-mysql-result-to-kml-file-output-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
