<?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>indexu.com &#187; google map</title>
	<atom:link href="http://www.indexu.com/tag/google-map/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.indexu.com</link>
	<description>developer blog</description>
	<lastBuildDate>Wed, 30 Jun 2010 05:06:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Adding dynamic gmap with navigation and zooming</title>
		<link>http://www.indexu.com/adding-dynamic-gmap-with-navigation-and-zooming/</link>
		<comments>http://www.indexu.com/adding-dynamic-gmap-with-navigation-and-zooming/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 00:34:12 +0000</pubDate>
		<dc:creator>dody</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Templates]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[google map]]></category>

		<guid isPermaLink="false">http://www.indexu.com/?p=26</guid>
		<description><![CDATA[As many of you request how to replace the static gmap image with dynamic gmap which allow navigation and zooming, I made some test how to do this for the easiest way. Ok. This is the easiest way. We only need to change the template files. Actually only 2 files. Edit header.html, usually we use [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.indexu.com/up/gmap1.png" alt="google map with navigation" title="google map with navigation" /></p>
<p>As many of you request how to replace the static gmap image with dynamic gmap which allow navigation and zooming, I made some test how to do this for the easiest way.</p>
<p>Ok. This is the easiest way. We only need to change the template files. Actually only 2 files.</p>
<p>Edit <code>header.html</code>, usually we use</p>

<div class="wp_codebox"><table><tr id="p265"><td class="code" id="p26code5"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span></pre></td></tr></table></div>

<p> but now we need to add <code>onload</code> call to js to load gmap only when detail page is accessed.</p>

<div class="wp_codebox"><table><tr id="p266"><td class="code" id="p26code6"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;%</span>php<span style="color: #000000; font-weight: bold;">%&gt;</span>
<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$page_identifier</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$page_identifier</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'detail.php'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">'&lt;body onload=&quot;initialize()&quot; onunload=&quot;GUnload()&quot;&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;&lt;body&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">&lt;%</span><span style="color: #339933;">/</span>php<span style="color: #000000; font-weight: bold;">%&gt;</span></pre></td></tr></table></div>

<p>Edit <code>detail_link.html</code>, add the <code>div</code> container to show the map, it must have id <code>gmapnav_canvas</code>.</p>

<div class="wp_codebox"><table><tr id="p267"><td class="code" id="p26code7"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h3.html"><span style="color: #000000; font-weight: bold;">h3</span></a>&gt;</span>Location Map<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h3.html"><span style="color: #000000; font-weight: bold;">h3</span></a>&gt;</span>
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;gmapnav_canvas&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;width: 640px; height: 400px;text-align:center;margin: 20px;&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span></pre></td></tr></table></div>

<p>Next, the last step is to construct the js code for google map. Edit <code>detail_link.html</code>, you can put the code at the of this file.</p>

<div class="wp_codebox"><table><tr id="p268"><td class="code" id="p26code8"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;%</span>php<span style="color: #000000; font-weight: bold;">%&gt;</span>
&nbsp;
  <span style="color: #000088;">$api_key</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$dbConn</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select * from idx_link where link_id = '<span style="color: #006699; font-weight: bold;">{$_REQUEST['linkid']}</span>' limit 1&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dbConn</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Execute</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$address</span>  <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Fields</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;address&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$city</span>  <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Fields</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;city&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$zip</span>  <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Fields</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;zip&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$state</span>  <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Fields</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;state&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$country</span>  <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Fields</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;country&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$loc</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/urlencode"><span style="color: #990000;">urlencode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$address</span>, <span style="color: #006699; font-weight: bold;">$city</span>, <span style="color: #006699; font-weight: bold;">$state</span>, <span style="color: #006699; font-weight: bold;">$zip</span>, <span style="color: #006699; font-weight: bold;">$country</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$api_req</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://maps.google.com/maps/geo?q='</span><span style="color: #339933;">.</span><span style="color: #000088;">$loc</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;key='</span><span style="color: #339933;">.</span><span style="color: #000088;">$api_key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;sensor=false&amp;output=csv'</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$api_result</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$api_req</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span><span style="color: #000088;">$api_result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'200'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$latlng</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$arr</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">','</span><span style="color: #339933;">.</span><span style="color: #000088;">$arr</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$gmap_js</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;
    &lt;script src=<span style="color: #000099; font-weight: bold;">\&quot;</span>http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;key=<span style="color: #006699; font-weight: bold;">{$api_key}</span><span style="color: #000099; font-weight: bold;">\&quot;</span> type=<span style="color: #000099; font-weight: bold;">\&quot;</span>text/javascript<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&lt;/script&gt;
    &lt;script type=<span style="color: #000099; font-weight: bold;">\&quot;</span>text/javascript<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;
    function initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById(<span style="color: #000099; font-weight: bold;">\&quot;</span>gmapnav_canvas<span style="color: #000099; font-weight: bold;">\&quot;</span>));
        map.setCenter(new GLatLng(<span style="color: #006699; font-weight: bold;">{$latlng}</span>), 10);
&nbsp;
        var latlng = new GLatLng(<span style="color: #006699; font-weight: bold;">{$latlng}</span>);
        map.addOverlay(new GMarker(latlng));
&nbsp;
        map.addControl(new GSmallMapControl());
      }
    }
   &lt;/script&gt;
    &quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">print</span> <span style="color: #000088;">$gmap_js</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">&lt;%</span><span style="color: #339933;">/</span>php<span style="color: #000000; font-weight: bold;">%&gt;</span></pre></td></tr></table></div>



<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-blogger">
			<a href="http://www.blogger.com/blog_this.pyra?t&amp;u=http://www.indexu.com/adding-dynamic-gmap-with-navigation-and-zooming/&amp;n=Adding+dynamic+gmap+with+navigation+and+zooming&amp;pli=1" rel="nofollow" class="external" title="Blog this on Blogger">Blog this on Blogger</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.indexu.com/adding-dynamic-gmap-with-navigation-and-zooming/&amp;title=Adding+dynamic+gmap+with+navigation+and+zooming" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.indexu.com/adding-dynamic-gmap-with-navigation-and-zooming/&amp;t=Adding+dynamic+gmap+with+navigation+and+zooming" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.indexu.com/adding-dynamic-gmap-with-navigation-and-zooming/&amp;title=Adding+dynamic+gmap+with+navigation+and+zooming" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="shr-squidoo">
			<a href="http://www.squidoo.com/lensmaster/bookmark?http://www.indexu.com/adding-dynamic-gmap-with-navigation-and-zooming/" rel="nofollow" class="external" title="Add to a lense on Squidoo">Add to a lense on Squidoo</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Adding+dynamic+gmap+with+navigation+and+zooming+-+http://b2l.me/3jf2y&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.indexu.com/adding-dynamic-gmap-with-navigation-and-zooming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

