<?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>The Tutorial Blog &#187; geocoding</title>
	<atom:link href="http://www.thetutorialblog.com/tag/geocoding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thetutorialblog.com</link>
	<description></description>
	<lastBuildDate>Tue, 08 Nov 2011 19:21:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<image>
<link>http://www.thetutorialblog.com</link>
<url>http://www.thetutorialblog.com/wp-content/plugins/maxblogpress-favicon/icons/favicon-28.ico</url>
<title>The Tutorial Blog</title>
</image>
		<item>
		<title>PHP Class for Google Maps API</title>
		<link>http://www.thetutorialblog.com/php/php-class-for-google-maps-api/</link>
		<comments>http://www.thetutorialblog.com/php/php-class-for-google-maps-api/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 15:18:06 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Text Tutorials]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[geocoding]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[latitude]]></category>
		<category><![CDATA[longitude]]></category>
		<category><![CDATA[php googlemapapi]]></category>
		<category><![CDATA[text tutorial]]></category>
		<category><![CDATA[the tutorial blog]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=92</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	A few days ago I was developing a website for a client. They required that there be a map showing where addresses are that were retrieved from a database. I have never properly looked at the Google Maps API before because I have never needed to use it; so for the first time I looked [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fphp-class-for-google-maps-api%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fphp-class-for-google-maps-api%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="PHP Class for Google Maps API" alt=" PHP Class for Google Maps API" /><br />
			</a>
		</div>
<p><img class="alignleft size-full wp-image-93" title="google_maps_logo_small_blue" src="http://www.thetutorialblog.com/wp-content/uploads/2009/07/google_maps_logo_small_blue.png" alt="google maps logo small blue PHP Class for Google Maps API" width="200" height="200" />A few days ago I was developing a website for a client. They required that there be a map showing where addresses are that were retrieved from a database. I have never properly looked at the Google Maps API before because I have never needed to use it; so for the first time I looked at it and gave it a try. Then after playing around with it for a bit i realised that reverse geocoding was needed to convert the address into latitude and longitude figures.</p>
<p>Because I was programming this website in PHP I thought I would have a look around for a PHP class to see if there was a quicker way of doing this. Luckily enough I found a PHP class called <a title="PHP GoogleMapAPI" href="http://www.phpinsider.com/php/code/GoogleMapAPI/" target="_blank">PHP GoogleMapAPI</a>. It took me a few minutes to read through the documentation for this class but it was so straight forward and simple. All in all it takes only 6 lines of code using this class to create a google map and locate it to an address; because it does all the other work for you that you don't need to know about if you're not going to be programming Google Maps every day of your life.</p>
<p><span id="more-92"></span></p>
<h2>Implementing Google Maps on your website</h2>
<p>The first thing you need to do is go to <a title="PHP GoogleMapAPI" href="http://www.phpinsider.com/php/code/GoogleMapAPI/" target="_blank">the website</a> and download the class. Then copy it into the directory where you keep your classes stored on your server.</p>
<p>When you have downloaded the class, it then needs to be included in the file that we want to show the map in. At the top of your file insert the code below.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GoogleMapAPI.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$map</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GoogleMapAPI<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'map'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// enter YOUR Google Map Key</span>
<span style="color: #000088;">$map</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAPIKey</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'YOURGOOGLEMAPKEY'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$map</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addMarkerByAddress</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'621 N 48th St # 6 Lincoln NE 68502'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Our Address'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'&lt;b&gt;Our Address&lt;/b&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>body onload<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;onLoad()&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$map</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">printMap</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>
&nbsp;
&lt;/body&gt;</pre></div></div>

<p>What we are doing here is including the class with the require function in PHP. If the class fails to be included then the rest of the page will stop executing.<br />
We then create a new instance of the class and then we insert.</p>
<p>If you have a Google Maps API key then insert it where it says 'YOURGOOGLEMAPKEY'. If you do not have one you can get one from <a href="http://code.google.com/apis/maps/signup.html" target="_blank">here</a>.</p>
<p>The function below adds a marker to the address you would like and centers it. This function takes 3 parameters; the address, a title and html.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$map</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addMarkerByAddress</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We then need to include the onLoad function so that it knows to load the map on this page.</p>
<p>The last function that we add is</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$map</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">printMap</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>Wherever you insert this function is where the map will be displayed on the page.</p>
<h2>Let us know</h2>
<p>I hope this tutorial has been useful and you have learned something new from it. Feel free to post a comment below and share your experience with this class or the Google Maps API.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/php/php-class-for-google-maps-api/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

