<?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>iphone and gis development notes</title>
	<atom:link href="http:///wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>/wordpress</link>
	<description>By Rupert</description>
	<lastBuildDate>Sun, 29 Aug 2010 22:44:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>iPhone Bug Note #1: Route-Me and Three20 in the same Project. _aasin dup symbol when building on iOS4</title>
		<link>/wordpress/2010/08/iphone-bug-note-1-route-me-and-three20-in-the-same-project-_aasin-dup-symbol-when-building-on-ios4/</link>
		<comments>/wordpress/2010/08/iphone-bug-note-1-route-me-and-three20-in-the-same-project-_aasin-dup-symbol-when-building-on-ios4/#comments</comments>
		<pubDate>Sat, 14 Aug 2010 06:46:32 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=754</guid>
		<description><![CDATA[It seems route-me and three20 doesn&#8217;t mix well on iOS4. When building my project (Philippines), I get an error on _aasin duplicate symbol, which was also discussed on route-me issue 138 at code.google.com Three20 needs linker flag shown below: -all_load The only way to go about this was linking proj4 directly from the project and]]></description>
			<content:encoded><![CDATA[<p>It seems route-me and three20 doesn&#8217;t mix well on iOS4. When building my project (Philippines), I get an error on _aasin duplicate symbol, which was also discussed <a href="http://code.google.com/p/route-me/issues/detail?id=138">on route-me issue 138 at code.google.com</a></p>
<p>Three20 needs linker flag shown below:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">-all_load</pre></div></div>

<p>The only way to go about this was linking proj4 directly from the project and removing it from route-me, thus no need to remove the &#8220;all_load&#8221; linker flag. Note: I tried removing the &#8220;all_load&#8221; linker flag from my project and it builds fine. However, the app crashes.</p>
<p>1. Drag the proj4.xcodeproj from RouteMe to your main project.</p>
<p>2. Afterwards delete the proj4.xcodeproj from RouteMe.<br />
<img src="/wordpress/wp-content/uploads/2010/08/RouteMe.png" alt="RouteMe.png" border="0" width="324" height="394" /></p>
<p>3. Your project should now reference both MapView and Proj4.<br />
<img src="/wordpress/wp-content/uploads/2010/08/three20.png" alt="three20.png" border="0" width="264" height="216" /></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2010/08/iphone-bug-note-1-route-me-and-three20-in-the-same-project-_aasin-dup-symbol-when-building-on-ios4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Dev Note #21: Route-Me Offline Mapping from Database</title>
		<link>/wordpress/2010/08/iphone-dev-note-21-route-me-offline-mapping-from-database/</link>
		<comments>/wordpress/2010/08/iphone-dev-note-21-route-me-offline-mapping-from-database/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 08:48:53 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>
		<category><![CDATA[sqlite3]]></category>

		<guid isPermaLink="false">/wordpress/?p=744</guid>
		<description><![CDATA[Part I: Download the osm (openstreetmap) tiles 1. Download the tiles from osm using downloadosmtiles.pl - Download Geo-OSM-Tiles-0.02.tar.gz from CPAN - See README file. Compile and build perl Makefile.PL make make test make install - Copy downloadosmtiles.pl to /usr/bin - Usage: downloadosmtiles.pl --lat=min_lat:max_lat --lon=min_long:max_long --zoom=min_zoom:max_zoom How do you set the min_lat, max_lat and min_long, max_long?]]></description>
			<content:encoded><![CDATA[<p><strong>Part I: Download the osm (<a href="www.openstreetmap.org">openstreetmap</a>) tiles</strong><br />
1. Download the tiles from osm using <a href="http://search.cpan.org/~rotkraut/Geo-OSM-Tiles-0.02/downloadosmtiles.pl">downloadosmtiles.pl</a><br />
- Download <a href="http://search.cpan.org/CPAN/authors/id/R/RO/ROTKRAUT/Geo-OSM-Tiles-0.02.tar.gz">Geo-OSM-Tiles-0.02.tar.gz from CPAN</a><br />
- See README file. Compile and build</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">   perl Makefile.PL
   make
   make test
   make install</pre></div></div>

<p>- Copy downloadosmtiles.pl to /usr/bin<br />
- Usage:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">downloadosmtiles.pl <span style="color: #660033;">--lat</span>=min_lat:max_lat <span style="color: #660033;">--lon</span>=min_long:max_long <span style="color: #660033;">--zoom</span>=min_zoom:max_zoom</pre></div></div>

<p>How do you set the min_lat, max_lat and min_long, max_long?<br />
- Go to <a href="www.openstreetmap.org">www.openstreetmap.org</a><br />
- Click on the &#8220;Edit&#8221; tab<br />
- You will see the extent or bounds of the map under the section &#8220;Area to Export&#8221;<br />
- Alternatively, you can click on &#8220;Manually select a different area&#8221; to specifically choose an area.</p>
<p><img src="/wordpress/wp-content/uploads/2010/08/osm.png" alt="osm.png" border="0" width="670" height="209" /></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">downloadosmtiles.pl <span style="color: #660033;">--lat</span>=<span style="color: #000000;">6.9443</span>:<span style="color: #000000;">7.2261</span> <span style="color: #660033;">--lon</span>=<span style="color: #000000;">125.5082</span>:<span style="color: #000000;">125.7104</span> <span style="color: #660033;">--zoom</span>=<span style="color: #000000;">6</span>:<span style="color: #000000;">12</span></pre></div></div>

<p>The tiles will be downloaded to the current directory.<br />
<img src="/wordpress/wp-content/uploads/2010/08/dir.png" alt="dir.png" border="0" width="153" height="206" /></p>
<p><strong>Part II:Put the tiles in the sqlite database</strong><br />
1. Read <a href="http://groups.google.com/group/route-me-map/browse_thread/thread/934459dc136ffd28">Frank&#8217;s email to route-me group regarding map2sqlite</a></p>
<p>2. Download <a href="http://groups.google.com/group/route-me-map/files">map2sqlite-1.0.tar.bz2</a>. </p>
<p>3. Build the map2sqlite XCodeProj. Afterwards, find map2sqlite and drop it in /usr/bin.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> map2sqlite <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin</pre></div></div>

<p>4. Run map2sqlite to import the tiles in sqlite.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">map2sqlite <span style="color: #660033;">-db</span> ph-1.0.0.db <span style="color: #660033;">-mapdir</span> ph-osm-map<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">24</span>:<span style="color: #000000;">40.749</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> map2sqlite <span style="color: #000000;">1.0</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">24</span>:<span style="color: #000000;">40.756</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Creating ph-1.0.0.db
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">24</span>:<span style="color: #000000;">40.761</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Importing map tiles at ph-osm-map<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.169</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> 
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.170</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Map statistics
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.170</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #660033;">--------------</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.171</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> map db:            ph-1.0.0.db
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.171</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #c20cb9; font-weight: bold;">size</span>:         <span style="color: #000000;">13758464</span> bytes
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.172</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> tile directory:    ph-osm-map<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.172</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> number of tiles:   <span style="color: #000000;">9091</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.173</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> zoom levels:       <span style="color: #000000;">6</span> - <span style="color: #000000;">11</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.218</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> zoom level  <span style="color: #000000;">6</span>:        <span style="color: #000000;">12</span> tiles, <span style="color: #7a0874; font-weight: bold;">&#40;</span>    <span style="color: #000000;">28</span>,    <span style="color: #000000;">52</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>x<span style="color: #7a0874; font-weight: bold;">&#40;</span>    <span style="color: #000000;">31</span>,    <span style="color: #000000;">54</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">112.500000</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">21.943047</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>x<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">129.375000</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">0.000000</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.219</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> zoom level  <span style="color: #000000;">7</span>:        <span style="color: #000000;">35</span> tiles, <span style="color: #7a0874; font-weight: bold;">&#40;</span>    <span style="color: #000000;">56</span>,   <span style="color: #000000;">105</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>x<span style="color: #7a0874; font-weight: bold;">&#40;</span>    <span style="color: #000000;">62</span>,   <span style="color: #000000;">109</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">115.312500</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">21.943047</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>x<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">129.375000</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">2.811371</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.222</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> zoom level  <span style="color: #000000;">8</span>:       <span style="color: #000000;">117</span> tiles, <span style="color: #7a0874; font-weight: bold;">&#40;</span>   <span style="color: #000000;">112</span>,   <span style="color: #000000;">210</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>x<span style="color: #7a0874; font-weight: bold;">&#40;</span>   <span style="color: #000000;">124</span>,   <span style="color: #000000;">218</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">115.312500</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">21.943047</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>x<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">127.968750</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">4.214943</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.223</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> zoom level  <span style="color: #000000;">9</span>:       <span style="color: #000000;">450</span> tiles, <span style="color: #7a0874; font-weight: bold;">&#40;</span>   <span style="color: #000000;">225</span>,   <span style="color: #000000;">420</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>x<span style="color: #7a0874; font-weight: bold;">&#40;</span>   <span style="color: #000000;">249</span>,   <span style="color: #000000;">437</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">115.312500</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">21.289375</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>x<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">127.968750</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">4.214943</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.225</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> zoom level <span style="color: #000000;">10</span>:      <span style="color: #000000;">1715</span> tiles, <span style="color: #7a0874; font-weight: bold;">&#40;</span>   <span style="color: #000000;">450</span>,   <span style="color: #000000;">841</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>x<span style="color: #7a0874; font-weight: bold;">&#40;</span>   <span style="color: #000000;">498</span>,   <span style="color: #000000;">875</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">115.664062</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">21.289375</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>x<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">127.968750</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">4.565474</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.231</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> zoom level <span style="color: #000000;">11</span>:      <span style="color: #000000;">6762</span> tiles, <span style="color: #7a0874; font-weight: bold;">&#40;</span>   <span style="color: #000000;">900</span>,  <span style="color: #000000;">1683</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>x<span style="color: #7a0874; font-weight: bold;">&#40;</span>   <span style="color: #000000;">997</span>,  <span style="color: #000000;">1751</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">115.839844</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">21.289375</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>x<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">127.968750</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">4.565474</span><span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>5. ph-osm-map is 43.9 MB but was compressed to ph-1.0.0.db (13.8 MB)</p>
<p><strong>Part III: Downlaod the route-me code from trunk and run some examples.</strong><br />
- Follow this <a href="/wordpress/2009/12/iphone-dev-note-19-route-me-an-opensource-mapkit-for-the-iphone/">previous tutorial</a></p>
<p><strong>Part IV: Patch the trunk to incorporate the RMDBMapSource from Frank Schroder</strong></p>
<p>1. What we need to add to the trunk. Download <a href="/wordpress/wp-content/uploads/2010/08/RMDBMapSource.zip" title="RMDBMapSource.zip">RMDBMapSource.zip</a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">+ RMDBMapSource.h
+ RMDBMapSource.m
+ RMDBTileImage.h
+ RMDBTileImage.m</pre></div></div>

<p>Copy the files above to the &#8220;Map&#8221; directory.</p>
<p><img src="/wordpress/wp-content/uploads/2010/08/route-me-1.png" alt="route-me-1.png" border="0" width="338" height="403" /></p>
<p>2. Edit RMTileImage.h and RMTileImage.m base on the patch below.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">Index<span style="color: #339933;">:</span> MapView<span style="color: #339933;">/</span>Map<span style="color: #339933;">/</span>RMTileImage.<span style="color: #202020;">h</span>
<span style="color: #339933;">===================================================================</span>
<span style="color: #339933;">---</span> MapView<span style="color: #339933;">/</span>Map<span style="color: #339933;">/</span>RMTileImage.<span style="color: #202020;">h</span>	<span style="color: #009900;">&#40;</span>revision <span style="color: #0000dd;">605</span><span style="color: #009900;">&#41;</span>
<span style="color: #339933;">+++</span> MapView<span style="color: #339933;">/</span>Map<span style="color: #339933;">/</span>RMTileImage.<span style="color: #202020;">h</span>	<span style="color: #009900;">&#40;</span>working copy<span style="color: #009900;">&#41;</span>
@@ <span style="color: #339933;">-</span><span style="color: #0000dd;">37</span><span style="color: #339933;">,</span><span style="color: #0000dd;">8</span> <span style="color: #339933;">+</span><span style="color: #0000dd;">37</span><span style="color: #339933;">,</span><span style="color: #0000dd;">10</span> @@
 <span style="color: #339933;">#import &quot;RMNotifications.h&quot;</span>
 <span style="color: #339933;">#import &quot;RMTile.h&quot;</span>
 <span style="color: #339933;">#import &quot;RMTileProxy.h&quot;</span>
<span style="color: #339933;">+</span><span style="color: #339933;">#import &quot;FMDatabase.h&quot;</span>
&nbsp;
 @class RMTileImage<span style="color: #339933;">;</span>
<span style="color: #339933;">+</span>@class NSData<span style="color: #339933;">;</span>
&nbsp;
 @interface RMTileImage <span style="color: #339933;">:</span> NSObject <span style="color: #009900;">&#123;</span>
 	<span style="color: #666666; font-style: italic;">// I know this is a bit nasty.</span>
@@ <span style="color: #339933;">-</span><span style="color: #0000dd;">64</span><span style="color: #339933;">,</span><span style="color: #0000dd;">6</span> <span style="color: #339933;">+</span><span style="color: #0000dd;">66</span><span style="color: #339933;">,</span><span style="color: #0000dd;">7</span> @@
 <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>RMTileImage<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>imageForTile<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>RMTile<span style="color: #009900;">&#41;</span> tile withURL<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>NSString<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>url<span style="color: #339933;">;</span>
 <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>RMTileImage<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>imageForTile<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>RMTile<span style="color: #009900;">&#41;</span> tile fromFile<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>NSString<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>filename<span style="color: #339933;">;</span>
 <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>RMTileImage<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>imageForTile<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>RMTile<span style="color: #009900;">&#41;</span> tile withData<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>NSData<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>data<span style="color: #339933;">;</span>
<span style="color: #339933;">++</span> <span style="color: #009900;">&#40;</span>RMTileImage<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>imageForTile<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>RMTile<span style="color: #009900;">&#41;</span> tile fromDB<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>FMDatabase<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>db<span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>moveBy<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>CGSize<span style="color: #009900;">&#41;</span> delta<span style="color: #339933;">;</span>
 <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>zoomByFactor<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">float</span><span style="color: #009900;">&#41;</span> zoomFactor near<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>CGPoint<span style="color: #009900;">&#41;</span> center<span style="color: #339933;">;</span>
Index<span style="color: #339933;">:</span> MapView<span style="color: #339933;">/</span>Map<span style="color: #339933;">/</span>RMTileImage.<span style="color: #202020;">m</span>
<span style="color: #339933;">===================================================================</span>
<span style="color: #339933;">---</span> MapView<span style="color: #339933;">/</span>Map<span style="color: #339933;">/</span>RMTileImage.<span style="color: #202020;">m</span>	<span style="color: #009900;">&#40;</span>revision <span style="color: #0000dd;">605</span><span style="color: #009900;">&#41;</span>
<span style="color: #339933;">+++</span> MapView<span style="color: #339933;">/</span>Map<span style="color: #339933;">/</span>RMTileImage.<span style="color: #202020;">m</span>	<span style="color: #009900;">&#40;</span>working copy<span style="color: #009900;">&#41;</span>
@@ <span style="color: #339933;">-</span><span style="color: #0000dd;">29</span><span style="color: #339933;">,</span><span style="color: #0000dd;">6</span> <span style="color: #339933;">+</span><span style="color: #0000dd;">29</span><span style="color: #339933;">,</span><span style="color: #0000dd;">7</span> @@
 <span style="color: #339933;">#import &quot;RMWebTileImage.h&quot;</span>
 <span style="color: #339933;">#import &quot;RMTileLoader.h&quot;</span>
 <span style="color: #339933;">#import &quot;RMFileTileImage.h&quot;</span>
<span style="color: #339933;">+</span><span style="color: #339933;">#import &quot;RMDBTileImage.h&quot;</span>
 <span style="color: #339933;">#import &quot;RMTileCache.h&quot;</span>
 <span style="color: #339933;">#import &quot;RMPixel.h&quot;</span>
 <span style="color: #339933;">#import &lt;QuartzCore/QuartzCore.h&gt;</span>
@@ <span style="color: #339933;">-</span><span style="color: #0000dd;">108</span><span style="color: #339933;">,</span><span style="color: #0000dd;">6</span> <span style="color: #339933;">+</span><span style="color: #0000dd;">109</span><span style="color: #339933;">,</span><span style="color: #0000dd;">11</span> @@
 	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#91;</span>image autorelease<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">++</span> <span style="color: #009900;">&#40;</span>RMTileImage<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>imageForTile<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>RMTile<span style="color: #009900;">&#41;</span> _tile fromDB<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>FMDatabase<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>db
<span style="color: #339933;">+</span><span style="color: #009900;">&#123;</span>
<span style="color: #339933;">+</span>	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>RMDBTileImage alloc<span style="color: #009900;">&#93;</span> initWithTile<span style="color: #339933;">:</span> _tile fromDB<span style="color: #339933;">:</span>db<span style="color: #009900;">&#93;</span> autorelease<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">+</span><span style="color: #009900;">&#125;</span>
<span style="color: #339933;">+</span>
 <span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> cancelLoading
 <span style="color: #009900;">&#123;</span>
 	<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>NSNotificationCenter defaultCenter<span style="color: #009900;">&#93;</span> postNotificationName<span style="color: #339933;">:</span>RMMapImageLoadingCancelledNotification</pre></div></div>

<p>We just need to add this line on RMTileImage.h:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">+<span style="color: #666666; font-style: italic;">#import &quot;FMDatabase.h&quot;</span>
...
++ <span style="color: #7a0874; font-weight: bold;">&#40;</span>RMTileImage<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>imageForTile: <span style="color: #7a0874; font-weight: bold;">&#40;</span>RMTile<span style="color: #7a0874; font-weight: bold;">&#41;</span> tile fromDB: <span style="color: #7a0874; font-weight: bold;">&#40;</span>FMDatabase<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>db;</pre></div></div>

<p>do the same for RMTileImage.m:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">+<span style="color: #666666; font-style: italic;">#import &quot;RMDBTileImage.h&quot;</span>
...
++ <span style="color: #7a0874; font-weight: bold;">&#40;</span>RMTileImage<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>imageForTile:<span style="color: #7a0874; font-weight: bold;">&#40;</span>RMTile<span style="color: #7a0874; font-weight: bold;">&#41;</span> _tile fromDB: <span style="color: #7a0874; font-weight: bold;">&#40;</span>FMDatabase<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>db
+<span style="color: #7a0874; font-weight: bold;">&#123;</span>
+	<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>RMDBTileImage alloc<span style="color: #7a0874; font-weight: bold;">&#93;</span> initWithTile: _tile fromDB:db<span style="color: #7a0874; font-weight: bold;">&#93;</span> autorelease<span style="color: #7a0874; font-weight: bold;">&#93;</span>;
+<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>4. Still with me? Comment NSAssert on 609 on RMMapContents.m<br />
<img src="/wordpress/wp-content/uploads/2010/08/rmcontents.png" alt="rmcontents.png" border="0" width="838" height="336" /></p>
<p><strong>Part V: RouteMeSampleMapDBOffline code</strong><br />
1. Download <a href="/wordpress/wp-content/uploads/2010/08/RouteMeSampleMapDBOffline.zip" title="RouteMeSampleMapDBOffline.zip">RouteMeSampleMapDBOffline.zip</a></p>
<p>2. Drop the project in the samples directory.<br />
<img src="/wordpress/wp-content/uploads/2010/08/sample_proj.png" alt="sample_proj.png" border="0" width="311" height="379" /></p>
<p>3. Build. You should be able to build this since the header path is relative to the route-me trunk.<br />
<img src="/wordpress/wp-content/uploads/2010/08/build-config.png" alt="build-config.png" border="0" width="480" height="338" /></p>
<p>4. Run from the simulator<br />
<img src="/wordpress/wp-content/uploads/2010/08/finish.png" alt="finish.png" border="0" width="393" height="733" /></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2010/08/iphone-dev-note-21-route-me-offline-mapping-from-database/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>What I&#8217;ve learned during the past two weeks (July 26 &#8211; Aug 8) in iOS Development?</title>
		<link>/wordpress/2010/08/what-ive-learned-during-the-past-two-weeks-july-26-aug-8-in-ios-development/</link>
		<comments>/wordpress/2010/08/what-ive-learned-during-the-past-two-weeks-july-26-aug-8-in-ios-development/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 23:46:03 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=731</guid>
		<description><![CDATA[1. WWDC 2010 Sample Code. I&#8217;ve totally missed the download link from iTunes so I&#8217;m listing it here just in case. Note: You need to be registered in the iPhone Developer Program. Check out the Video Access List to know which videos are available for each developer program. 2. AdvancedTableViewCells &#8211; sample code provided by]]></description>
			<content:encoded><![CDATA[<p>1. <a href="http://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/getSoftware?code=y&#038;source=x&#038;bundleID=20645"><strong>WWDC 2010 Sample Code.</strong></a> I&#8217;ve totally missed the download link from iTunes so I&#8217;m listing it here just in case. Note: You need to be registered in the iPhone Developer Program.  Check out the <a href="http://developer.apple.com/videos/access/">Video Access List</a> to know which videos are available for each developer program.</p>
<p>2. <strong>AdvancedTableViewCells</strong> &#8211; sample code provided by WWDC 2010 which explains several ways how to subclass a UITableViewCell.<br />
- iPhone Development Foundation Videos: &#8220;Session 432 &#8211; Mastering iPhone Table Views&#8221;<br />
- WWDC 2010 Session Video: &#8220;Session 128 &#8211; Mastering Table Views&#8221;<br />
- IndividualSubviewsBasedApplicaionCell uses a sib<br />
- CompositeSubviewBasedApplicationCell uses a custom view to drall all UI in drawRect<br />
- HybridSubviewBasedApplicationCell = CompositeSubviewBasedApplicationCell + custom UI elements during init. </p>
<p>3. <a href="http://apiblog.youtube.com/2009/02/youtube-apis-iphone-cool-mobile-apps.html"><strong>Play YouTube videos without exiting the application.</strong></a><br />
- Uses a webview to embed a youtube link.<br />
- Doesn&#8217;t work on the simulator. Need to test on actual device</p>
<p>4. <strong>Black based Animations</strong><br />
- WWDC 2010 Session Videos HD: &#8220;Session 128 &#8211; Building Animation Driven Interfaces&#8221;<br />
- It&#8217;s better to use block based animations than old style UIViewAnimations. Look at code below, after animations on the first block completes, displayContentOnPoiBoard executes..</p>

<div class="wp_syntax"><div class="code"><pre class="obj-c" style="font-family:monospace;">	[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationCurveEaseOut animations:^{
		viewPoiBoard.frame = newFrame;
		viewPoiBoard.alpha = 0.8;
		buttonMapNearby.alpha = 0;
		buttonMapDropPin.alpha = 0;
		segmentedControlMapType.alpha = 0;
	}completion:^(BOOL finished){
		[self displayContentOnPoiBoard:currentPoi];
	}];</pre></div></div>

<p>5. <strong>Beta Testing using AdHoc Distribution</strong><br />
- WWDC 2010 Session Video: &#8220;Session 310 &#8211; App Publishing with iTunes Connect&#8221;<br />
- <a href="http://developer.apple.com/iphone/download.action?path=/iphone/iphone_developer_program_user_guides/iphone_developer_program_user_guide__standard_program_v2.6__final_3410.pdf">iTunes Connect Program User Guide</a></p>
<p>Procedure:<br />
1. From the Provisioning Portal, Add the devices<br />
2. Create an AdHoc Distribution Provisioning Profile<br />
3. Use Adhoc.mobileprovision in XCode under codesigning<br />
4. Add an Entitlements.plist<br />
5. Build<br />
6. Try &#8220;Build and Archive&#8221;<br />
- this is new in XCode, under &#8220;Archived Applications&#8221;, which is actually cool as you can immediately save the ipa file under &#8220;Share Application&#8230;&#8221;<br />
<img src="/wordpress/wp-content/uploads/2010/08/xcode_archived_app.png" alt="xcode_archived_app.png" border="0" width="302" height="102" /><br />
7. Before I have to give out the Adhoc.mobileprovision as well, but now the ipa file is already sufficient.</p>
<p>6. <strong>iTunes Connect &#8220;New Version&#8221;</strong><br />
- <a href="http://developer.apple.com/iphone/news/archives/2010/july/">Important Information about Submitting Your Apps to iTunes Connect</a><br />
- Provide a version number and add metadata information e.g (&#8220;What&#8217;s New in this Version?). Once finished with all the metadata changes, click on &#8220;Ready to Upload Binary&#8221; and the App Status changes to &#8220;Waiting For Upload&#8221;.<br />
- Upload the binary thru XCode, see next step.</p>
<p>7. <strong>Appstore Distribution Binary Submission</strong><br />
- Follow the instructions on Beta Testing (5) but instead use an Appstore Distribution Provisioning Profile instead.<br />
- Trying &#8220;Build and Archive&#8221;, we can now &#8220;Validate Application&#8221; which validates the binary after providing your iTunes Connect username, password.<br />
- &#8220;Submit Application to iTunes Connect&#8221; uploads the binary and changes the status to &#8220;Upload Received&#8221; then &#8220;Waiting For Review&#8221;.</p>
<p>8. <strong>Control when your app goes live</strong><br />
<a href="http://developer.apple.com/iphone/news/archives/2010/august/#appupdategoeslive">You Can Now Control When Your App Update Goes Live</a><br />
- Pretty nifty stuff as you can now control when a version goes live, I notice there is a new &#8220;Release Control&#8221; which states &#8220;Hold for Developer Release&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2010/08/what-ive-learned-during-the-past-two-weeks-july-26-aug-8-in-ios-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Note #14: Drawing a Point, Line, Polygon on top of MKMapview</title>
		<link>/wordpress/2010/08/iphone-devnote-14-drawing-a-point-line-polygon-on-top-of-mkmapview/</link>
		<comments>/wordpress/2010/08/iphone-devnote-14-drawing-a-point-line-polygon-on-top-of-mkmapview/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 15:00:49 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=534</guid>
		<description><![CDATA[UPDATE: Aug 9, 2010 DrawMap2.zip Note: This does not contain the new MapKit functions for overlaying lines and polygons. This zip was created to compile against 4.0.0 but still have the same codebase. ============================ This is an update to iPhone DevNote #13. This post has solved my zooming/panning problem with a CustomView on top of]]></description>
			<content:encoded><![CDATA[<p>UPDATE: Aug 9, 2010<br />
<a href="/wordpress/wp-content/uploads/2010/08/DrawMap2.zip" title="DrawMap2.zip">DrawMap2.zip</a><br />
Note: This does not contain the new MapKit functions for overlaying lines and polygons. This zip was created to compile against 4.0.0 but still have the same codebase.<br />
============================</p>
<p>This is an update to <a href="">iPhone DevNote #13.</a> This post has solved my zooming/panning problem with a CustomView on top of my MKMapView courtesy of <a href="http://spitzkoff.com/craig/?p=108">http://spitzkoff.com/craig/?p=108 (Craig&#8217;s blog)</a>.  </p>
<p>The trick here is instead of doing the drawing on the drawRect method of the CustomView, we will use <a href="http://spitzkoff.com/craig/?p=108">Craig&#8217;s methodology</a> to use the drawRect method of a custom MKAnnotationView.  Note, that he also used an internal view and made clipsToBounds = NO, this way we can draw the whole geometry on top of MKMapView not just a portion of it. The end result is the shape (polygon in this example) is below the added pins.</p>
<p><img src="/wordpress/wp-content/uploads/2009/10/polygon_on_top_mapview.png" alt="polygon_on_top_mapview.png" border="0" width="250" height="372" /></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> LinePolygonAnnotationInternalView <span style="color: #002200;">:</span> UIView
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// line view which added this as a subview. </span>
	LinePolygonAnnotationView<span style="color: #002200;">*</span> _mainView;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> LinePolygonAnnotationView<span style="color: #002200;">*</span> mainView;
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> LinePolygonAnnotationInternalView
&nbsp;
<span style="color: #a61390;">@synthesize</span> mainView <span style="color: #002200;">=</span> _mainView;
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> init
<span style="color: #002200;">&#123;</span>
	self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;
	self.backgroundColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor clearColor<span style="color: #002200;">&#93;</span>;
	self.clipsToBounds <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
&nbsp;
	<span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> drawRect<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGRect<span style="color: #002200;">&#41;</span> rect
<span style="color: #002200;">&#123;</span>
	GeometryAnnotation<span style="color: #002200;">*</span> myAnnotation <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>GeometryAnnotation<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>self.mainView.annotation;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// only draw our lines if we're not int he moddie of a transition and we </span>
	<span style="color: #11740a; font-style: italic;">// acutally have some points to draw. </span>
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span>self.hidden <span style="color: #002200;">&amp;&amp;</span> <span style="color: #a61390;">nil</span> <span style="color: #002200;">!=</span> myAnnotation.points <span style="color: #002200;">&amp;&amp;</span> myAnnotation.points.count &gt; <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
		CGContextRef context <span style="color: #002200;">=</span> UIGraphicsGetCurrentContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>; 
&nbsp;
		<span style="color: #11740a; font-style: italic;">// Drawing lines with a white stroke color</span>
		CGContextSetRGBStrokeColor<span style="color: #002200;">&#40;</span>context, <span style="color: #2400d9;">1.0</span>, <span style="color: #2400d9;">1.0</span>, <span style="color: #2400d9;">1.0</span>, <span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#41;</span>;
&nbsp;
		<span style="color: #11740a; font-style: italic;">// Draw them with a 2.0 stroke width so they are a bit more visible.</span>
		CGContextSetLineWidth<span style="color: #002200;">&#40;</span>context, <span style="color: #2400d9;">2.0</span><span style="color: #002200;">&#41;</span>;		
&nbsp;
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>myAnnotation.geometryType <span style="color: #002200;">==</span> kGeometryTypePolygon<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
			CGContextSetRGBFillColor<span style="color: #002200;">&#40;</span>context, <span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">1.0</span>, <span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#41;</span>;
		<span style="color: #002200;">&#125;</span>
&nbsp;
		<span style="color: #11740a; font-style: italic;">// Draw them with a 2.0 stroke width so they are a bit more visible.</span>
		CGContextSetLineWidth<span style="color: #002200;">&#40;</span>context, <span style="color: #2400d9;">2.0</span><span style="color: #002200;">&#41;</span>;
&nbsp;
		<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> idx <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; idx &lt; myAnnotation.points.count; idx<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span>
		<span style="color: #002200;">&#123;</span>
			CLLocation<span style="color: #002200;">*</span> location <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>myAnnotation.points objectAtIndex<span style="color: #002200;">:</span>idx<span style="color: #002200;">&#93;</span>;
			CGPoint point <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self.mainView.mapView convertCoordinate<span style="color: #002200;">:</span>location.coordinate toPointToView<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
&nbsp;
			NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Point: %lf, %lf&quot;</span>, point.x, point.y<span style="color: #002200;">&#41;</span>;
&nbsp;
			<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>idx <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>
			<span style="color: #002200;">&#123;</span>
				<span style="color: #11740a; font-style: italic;">// move to the first point</span>
				CGContextMoveToPoint<span style="color: #002200;">&#40;</span>context, point.x, point.y<span style="color: #002200;">&#41;</span>;
			<span style="color: #002200;">&#125;</span>
			<span style="color: #a61390;">else</span>
			<span style="color: #002200;">&#123;</span>
				CGContextAddLineToPoint<span style="color: #002200;">&#40;</span>context, point.x, point.y<span style="color: #002200;">&#41;</span>;
			<span style="color: #002200;">&#125;</span>
		<span style="color: #002200;">&#125;</span>
&nbsp;
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>myAnnotation.geometryType <span style="color: #002200;">==</span> kGeometryTypeLine<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
			CGContextStrokePath<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;
		<span style="color: #002200;">&#125;</span>
		<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>myAnnotation.geometryType <span style="color: #002200;">==</span> kGeometryTypePolygon<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
			CGContextClosePath<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;
&nbsp;
			CGContextDrawPath<span style="color: #002200;">&#40;</span>context, kCGPathFillStroke<span style="color: #002200;">&#41;</span>;
		<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #002200;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> dealloc
<span style="color: #002200;">&#123;</span>
	self.mainView <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> LinePolygonAnnotationView
&nbsp;
<span style="color: #a61390;">@synthesize</span> mapView <span style="color: #002200;">=</span> _mapView;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>initWithFrame<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGRect<span style="color: #002200;">&#41;</span>frame <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super initWithFrame<span style="color: #002200;">:</span>frame<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
&nbsp;
		self.backgroundColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor clearColor<span style="color: #002200;">&#93;</span>;
&nbsp;
		<span style="color: #11740a; font-style: italic;">// do not clip the bounds. We need the LinePolygonAnnotationInternalView to be able to render the whole line/polygon, regardless of where the</span>
		<span style="color: #11740a; font-style: italic;">// actual annotation view is displayed. </span>
		self.clipsToBounds <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
&nbsp;
		<span style="color: #11740a; font-style: italic;">// create the internal line view that does the rendering of the line. </span>
		_internalView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>LinePolygonAnnotationInternalView alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
		_internalView.mainView <span style="color: #002200;">=</span> self;
&nbsp;
		<span style="color: #002200;">&#91;</span>self addSubview<span style="color: #002200;">:</span>_internalView<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> setMapView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>MKMapView<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> mapView
<span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>_mapView release<span style="color: #002200;">&#93;</span>;
	_mapView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>mapView retain<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>self regionChanged<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> regionChanged
<span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Region Changed&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// move the internal line view. </span>
	CGPoint origin <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>;
	origin <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>_mapView convertPoint<span style="color: #002200;">:</span>origin toView<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
&nbsp;
	_internalView.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span>origin.x, origin.y, _mapView.frame.size.width, _mapView.frame.size.height<span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#91;</span>_internalView setNeedsDisplay<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>dealloc 
<span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>_mapView release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>_internalView release<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>I extended the class above to be able to draw both lines and polygons by checking a property (geometryType) of the GeometryAnnotation. If the geometryType is a line, then just stroke the path. However, if the geometryType is a polygon, then close the path and fill it.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>myAnnotation.geometryType <span style="color: #002200;">==</span> kGeometryTypeLine<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
	CGContextStrokePath<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>myAnnotation.geometryType <span style="color: #002200;">==</span> kGeometryTypePolygon<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
	CGContextClosePath<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;
&nbsp;
	CGContextDrawPath<span style="color: #002200;">&#40;</span>context, kCGPathFillStroke<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>And here is the GeometryAnnotation class. Most of the code is from <a href="http://spitzkoff.com/craig/?p=108">Craig</a>, i just added the geometryType property:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//  Created by Craig on 8/18/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright Craig Spitzkoff 2009. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;GeometryAnnotation.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> GeometryAnnotation
<span style="color: #a61390;">@synthesize</span> coordinate <span style="color: #002200;">=</span> _center;
<span style="color: #a61390;">@synthesize</span> points <span style="color: #002200;">=</span> _points; 
<span style="color: #a61390;">@synthesize</span> annotationID;
<span style="color: #a61390;">@synthesize</span> geometryType;
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> initWithPoints<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> points withGeometry<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>GeometryType<span style="color: #002200;">&#41;</span>geomType
<span style="color: #002200;">&#123;</span>
	self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;
&nbsp;
	geometryType <span style="color: #002200;">=</span> geomType;
&nbsp;
	_points <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> alloc<span style="color: #002200;">&#93;</span> initWithArray<span style="color: #002200;">:</span>points<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// create a unique ID for this line so it can be added to dictionaries by this key. </span>
	self.annotationID <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%p&quot;</span>, self<span style="color: #002200;">&#93;</span>;
&nbsp;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// determine a logical center point for this line based on the middle of the lat/lon extents.</span>
	<span style="color: #a61390;">double</span> maxLat <span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">91</span>;
	<span style="color: #a61390;">double</span> minLat <span style="color: #002200;">=</span>  <span style="color: #2400d9;">91</span>;
	<span style="color: #a61390;">double</span> maxLon <span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">181</span>;
	<span style="color: #a61390;">double</span> minLon <span style="color: #002200;">=</span>  <span style="color: #2400d9;">181</span>;
&nbsp;
	<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span>CLLocation<span style="color: #002200;">*</span> currentLocation <span style="color: #a61390;">in</span> _points<span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
		CLLocationCoordinate2D coordinate <span style="color: #002200;">=</span> currentLocation.coordinate;
&nbsp;
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>coordinate.latitude &gt; maxLat<span style="color: #002200;">&#41;</span>
			maxLat <span style="color: #002200;">=</span> coordinate.latitude;
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>coordinate.latitude &lt; minLat<span style="color: #002200;">&#41;</span>
			minLat <span style="color: #002200;">=</span> coordinate.latitude;
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>coordinate.longitude &gt; maxLon<span style="color: #002200;">&#41;</span>
			maxLon <span style="color: #002200;">=</span> coordinate.longitude;
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>coordinate.longitude &lt; minLon<span style="color: #002200;">&#41;</span>
			minLon <span style="color: #002200;">=</span> coordinate.longitude; 
	<span style="color: #002200;">&#125;</span>
&nbsp;
	_span.latitudeDelta <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>maxLat <span style="color: #002200;">+</span> <span style="color: #2400d9;">90</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>minLat <span style="color: #002200;">+</span> <span style="color: #2400d9;">90</span><span style="color: #002200;">&#41;</span>;
	_span.longitudeDelta <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>maxLon <span style="color: #002200;">+</span> <span style="color: #2400d9;">180</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>minLon <span style="color: #002200;">+</span> <span style="color: #2400d9;">180</span><span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// the center point is the average of the max and mins</span>
	_center.latitude <span style="color: #002200;">=</span> minLat <span style="color: #002200;">+</span> _span.latitudeDelta <span style="color: #002200;">/</span> <span style="color: #2400d9;">2</span>;
	_center.longitude <span style="color: #002200;">=</span> minLon <span style="color: #002200;">+</span> _span.longitudeDelta <span style="color: #002200;">/</span> <span style="color: #2400d9;">2</span>;
&nbsp;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Found center of new Annotation at %lf, %ld&quot;</span>, _center.latitude, _center.longitude<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>MKCoordinateRegion<span style="color: #002200;">&#41;</span> region
<span style="color: #002200;">&#123;</span>
	MKCoordinateRegion region;
	region.center <span style="color: #002200;">=</span> _center;
	region.span <span style="color: #002200;">=</span> _span;
&nbsp;
	<span style="color: #a61390;">return</span> region;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> dealloc
<span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>_points release<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Now that we have a way to draw a line/polygon as a custom MKAnnotationView, we need a custom TouchView (GeometryTouchView) which could accept the touch events. </p>
<p>For example, if the user wants to draw a line geometry, the GeometryTouchView would accept touch events from the user and add a point as a PointAnnotation in the Map.  Succeeding points would be added to an array. For every point added, the MKAnnotationView drawRects method connects the points to produce a line.  The MKAnnotationView is now added to the map. </p>
<p>Once the geometry is added as an annotation, the custom TouchView is hidden. This way we have access (panning/zooming) to the mapview.  If we make a pan or a zoom, the region changes, thus we need to redraw the shape of the annotation again.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>mapView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>MKMapView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>mapView regionWillChangeAnimated<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>animated
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>currentAnnotationView <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
		NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;regionWillChangeAnimated&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
		currentAnnotationView.hidden <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>mapView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>MKMapView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>mapView regionDidChangeAnimated<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>animated
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>currentAnnotationView <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
		NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;regionDidChangeAnimated&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
		currentAnnotationView.hidden <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
		<span style="color: #002200;">&#91;</span>currentAnnotationView regionChanged<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> regionChanged
<span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Region Changed&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// move the internal line view. </span>
	CGPoint origin <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>;
	origin <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>_mapView convertPoint<span style="color: #002200;">:</span>origin toView<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
&nbsp;
	_internalView.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span>origin.x, origin.y, _mapView.frame.size.width, _mapView.frame.size.height<span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#91;</span>_internalView setNeedsDisplay<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>The resulting image is now:<br />
<img src="/wordpress/wp-content/uploads/2009/10/polygon_small_on_top_of_mapview.png" alt="polygon_small_on_top_of_mapview.png" border="0" width="250" height="372" /></p>
<p>(Download the <a href="/wordpress/wp-content/uploads/2009/10/DrawMap.zip" title="DrawMap.zip">DrawMap.zip</a> code.) &#8211; old. This is for iOS < 4</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2010/08/iphone-devnote-14-drawing-a-point-line-polygon-on-top-of-mkmapview/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>iPhone Cross Application Launch/Marketing Strategy</title>
		<link>/wordpress/2010/07/iphone-cross-application-launchmarketing-strategy/</link>
		<comments>/wordpress/2010/07/iphone-cross-application-launchmarketing-strategy/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 23:42:02 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[business]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=714</guid>
		<description><![CDATA[As many developers keep on asking me how I reached the rankings I have now for MyTravelPhilippines, I would like to share the marketing/launch strategy that we did. The strategy is not new. I&#8217;ve read from numerous iphone developer blogs who have a few apps in the store about cross app promotion. But how do]]></description>
			<content:encoded><![CDATA[<p>As many developers keep on asking me how I reached the rankings I have now for <a href="http://www.mytravelphilippines.com/">MyTravelPhilippines</a>, I would like to share the marketing/launch strategy that we did. The strategy is not new. I&#8217;ve read from numerous iphone developer blogs who have a few apps in the store about cross app promotion. But how do you really do it?</p>
<p>On Dec 2009, I have released the &#8220;Philippines 2010 Election Survey&#8221;.  The red dot is on May 11 which is the actual elections for the Philippines. However after this event, you can see the downloads went down.. well because the elections are over&#8230;<br />
<img src="/wordpress/wp-content/uploads/2010/07/photo1.jpg" alt="photo1.jpg" border="0" width="480" height="320" /></p>
<p>When the election results came out from the government, I immediately made the app, &#8220;Philippines 2010 Election Results&#8221;. I have launched this on June 26. I was hoping that most users would be eager to see the results and most did update to the new app. Within the updated app, I made a link to download &#8220;MyTravelPhilippines&#8221; in the appstore.<br />
<img src="/wordpress/wp-content/uploads/2010/07/photo3.png" alt="photo3.png" border="0" width="320" height="480" /></p>
<p>The election app has a total of 4k users where 25% updated. Consequently, the &#8220;MyTravelPhilippines&#8221; eyeball did do the trick and on June 26 we had 849 downloads.<br />
<img src="/wordpress/wp-content/uploads/2010/07/photo2.jpg" alt="photo2.jpg" border="0" width="480" height="320" /></p>
<p>The 849 downloads on June 26 was significant as it was able to push &#8220;MyTravelPhilippines&#8221; to rank #1(Free Philippines Travel Category) and rank #9 (Free Philippines Overall).<br />
<img src="/wordpress/wp-content/uploads/2010/07/photo4.jpg" alt="photo4.jpg" border="0" width="320" height="480" /></p>
<p>In just two weeks, I was able to hit 5k mark for MyTravelPhilippines which took me 6 months to do in the Philippines Elections app.</p>
<p>What I&#8217;ve learned?<br />
- Use an <strong>event</strong>, in this case the <em>election results</em>, to get most out of the updates.<br />
- Cross app promotion works. It&#8217;s like migrating your users from one app to another.<br />
- Application Visibility is very important. Try hard to make it to the Top 10 in that category. (Yes, I know its easier said that done.. but really aim for this..)</p>
<p>What I&#8217;ve missed?<br />
<strong>Application updates to keep the app alive.</strong> This would help in <em>&#8220;the download and never open again or open occasionally syndrome&#8221;</em>. At the time of this writing, I am currently trying to do this as I could see the graph is slowly trending down. What I should have anticipated is to keep at least one version higher (1.1) and uploading the older version(1.0) on the store. The timing of this updates could be periodical&#8211;after 3 weeks, a month or an event. But with the limited resources that we had, only a two man team, and no marketing $$$ expense at all in ads, it was a great experience.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2010/07/iphone-cross-application-launchmarketing-strategy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blogging, MyTravelPhilippines, Navteq</title>
		<link>/wordpress/2010/07/blogging-mytravelphilippines-navteq/</link>
		<comments>/wordpress/2010/07/blogging-mytravelphilippines-navteq/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 00:24:09 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[business]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">/wordpress/?p=710</guid>
		<description><![CDATA[I have neglected this blog for the past few months because of the past activities I was involved in. It was a fruitful year for the iPhone as I have launched two successful and rewarding projects. 1. The iphone app for a client in the beforeYouDig industry has extremely improved over the past 6 months.]]></description>
			<content:encoded><![CDATA[<p>I have neglected this blog for the past few months because of the past activities I was involved in. It was a fruitful year for the iPhone as I have launched two successful and rewarding projects. </p>
<p>1. The iphone app for a client in the beforeYouDig industry has extremely improved over the past 6 months. It has won <a href="http://corporate.navteq.com/webapps/NewsUserServlet?action=NewsDetail&#038;newsId=897&#038;lang=en&#038;englishonly=false">second place in the Navteq LBS Challenge for APAC.</a> If you have been following my posts, this was related to route-me. Hopefully, we should launch this in the AppStore soon. Stay tuned&#8230;</p>
<p>2. <a href="http://www.mytravelphilippines.com">MyTravelPhilippines</a> was launched last April on the web. After that, I started working on the mobile version on the iPhone. I pushed it in the store on June 15 and became Top 10 Free after a week in the PH store, and Top 1 in Travel Free category for the PH store. This was really great as we haven&#8217;t spent any $$$ on the marketing and relied on friends, facebook, etc for viral marketing. I am pushing again for another release before this month ends. Again, stay tuned.</p>
<p>So to break the ice.. I will be blogging again&#8230; </p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2010/07/blogging-mytravelphilippines-navteq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Note #14: QuickStart Tutorial</title>
		<link>/wordpress/2010/02/ruby-on-rails-quickstart-tutorial/</link>
		<comments>/wordpress/2010/02/ruby-on-rails-quickstart-tutorial/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 05:39:31 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">/wordpress/?p=707</guid>
		<description><![CDATA[If you haven&#8217;t installed ruby, follow this post Part 1: Installation and Configuration (Rails and Passenger) 1. Upgrade existing ruby gems sudo gem list sudo gem update --system UPDATE: Took me 4 hours figuring this out. There was a problem when i run script/console that it will say the &#8220;gem&#8221; detected was 1.0.1 although the]]></description>
			<content:encoded><![CDATA[<p>If you haven&#8217;t installed ruby, follow this <a href="/wordpress/2008/11/getting-my-feet-wet-in-ruby-on-rails/">post</a></p>
<p><strong>Part 1: Installation and Configuration (Rails and Passenger)</strong></p>
<p>1. Upgrade existing ruby gems</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem list
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem update <span style="color: #660033;">--system</span></pre></div></div>

<p>UPDATE: Took me 4 hours figuring this out. There was a problem when i run script/console that it will say the &#8220;gem&#8221; detected was 1.0.1 although the current gem version is 1.3.5 after gem update &#8211;system. Google didn&#8217;t helped out. But I was able to nail down the problem from this post:</p>
<p><a href="https://wincent.com/wiki/Upgrading_to_RubyGems_1.0.1_on_Mac_OS_X_10.5.1">https://wincent.com/wiki/Upgrading_to_RubyGems_1.0.1_on_Mac_OS_X_10.5.1</a><br />
In the post above, notice that rubygems 1.0.1 was installed in /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin. I guess this gem was being referenced first before the actual /usr/local/bin/gem. So I deleted this directory /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr.</p>
<p>Possible sources of gem installations:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>.gem<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems
<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Ruby<span style="color: #000000; font-weight: bold;">/</span>Gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rupert:<span style="color: #000000;">1.8</span> rupert$ gem <span style="color: #c20cb9; font-weight: bold;">env</span>
RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.5
  - RUBY VERSION: 1.8.6 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2008</span>-08-08 patchlevel <span style="color: #000000;">286</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>i686-darwin9.5.0<span style="color: #7a0874; font-weight: bold;">&#93;</span>
  - INSTALLATION DIRECTORY: <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span>
  - RUBY EXECUTABLE: <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby
  - EXECUTABLE DIRECTORY: <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-darwin-<span style="color: #000000;">9</span>
  - GEM PATHS:
     - <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span>
     - <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>.gem<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span>
  - GEM CONFIGURATION:
     - :update_sources =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">true</span>
     - :verbose =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">true</span>
     - :benchmark =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">false</span>
     - :backtrace =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">false</span>
     - :bulk_threshold =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000;">1000</span>
  - REMOTE SOURCES:
     - http:<span style="color: #000000; font-weight: bold;">//</span>gems.rubyforge.org<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>2. Install rails. Download from ruby-forge. Link?</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-V</span> rails-2.3.3.gem
gem <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-V</span> mysql</pre></div></div>

<p>3. Install and configure passenger for Apache2</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-V</span> passenger
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>.gem<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>passenger-2.2.5<span style="color: #000000; font-weight: bold;">/</span>bin
passenger-install-apache2-module</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">469 LoadModule passenger_module /Users/rupert/.gem/ruby/1.8/gems/passenger-2.2.5/ext/apache2/mod_passenger.so
470 PassengerRoot /Users/rupert/.gem/ruby/1.8/gems/passenger-2.2.5
471 PassengerRuby /usr/local/bin/ruby
472 
473 &lt;VirtualHost *:80&gt;
474   RailsBaseURI /rails/travelsiteph
475 &lt;/VirtualHost&gt;</pre></div></div>

<p>4. Create a sample rails project (&#8220;travelsiteph&#8221;) in your project directory (&#8220;/Users/rupert/projects/rails&#8221;).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>rails
$ rails travelisteph
      create  
      create  app<span style="color: #000000; font-weight: bold;">/</span>controllers
      create  app<span style="color: #000000; font-weight: bold;">/</span>helpers
      create  app<span style="color: #000000; font-weight: bold;">/</span>models
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>layouts
      create  config<span style="color: #000000; font-weight: bold;">/</span>environments
	.....
$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-la</span> travelsiteph
drwxr-xr-x  <span style="color: #000000;">15</span> rupert  admin    <span style="color: #000000;">510</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> .
drwxr-xr-x   <span style="color: #000000;">5</span> rupert  admin    <span style="color: #000000;">170</span> <span style="color: #000000;">30</span> Sep <span style="color: #000000;">16</span>:<span style="color: #000000;">31</span> ..
<span style="color: #660033;">-rw-r--r--</span>   <span style="color: #000000;">1</span> rupert  admin  <span style="color: #000000;">10011</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> README
<span style="color: #660033;">-rw-r--r--</span>   <span style="color: #000000;">1</span> rupert  admin    <span style="color: #000000;">307</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> Rakefile
drwxr-xr-x   <span style="color: #000000;">6</span> rupert  admin    <span style="color: #000000;">204</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> app
drwxr-xr-x   <span style="color: #000000;">9</span> rupert  admin    <span style="color: #000000;">306</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> config
drwxr-xr-x   <span style="color: #000000;">4</span> rupert  admin    <span style="color: #000000;">136</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">18</span> db
drwxr-xr-x   <span style="color: #000000;">3</span> rupert  admin    <span style="color: #000000;">102</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> doc
drwxr-xr-x   <span style="color: #000000;">3</span> rupert  admin    <span style="color: #000000;">102</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> lib
drwxr-xr-x   <span style="color: #000000;">6</span> rupert  admin    <span style="color: #000000;">204</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> log
drwxr-xr-x  <span style="color: #000000;">11</span> rupert  admin    <span style="color: #000000;">374</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> public
drwxr-xr-x  <span style="color: #000000;">11</span> rupert  admin    <span style="color: #000000;">374</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> script
drwxr-xr-x   <span style="color: #000000;">8</span> rupert  admin    <span style="color: #000000;">272</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">55</span> <span style="color: #7a0874; font-weight: bold;">test</span>
drwxr-xr-x   <span style="color: #000000;">6</span> rupert  admin    <span style="color: #000000;">204</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">22</span>:07 tmp
drwxr-xr-x   <span style="color: #000000;">3</span> rupert  admin    <span style="color: #000000;">102</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> vendor</pre></div></div>

<p>I have /wwwroot as my document WebRoot. Its running cf, php and mapserv (cgi-bin). Since I want to mix it with rails development, I&#8217;ll just make a rails subdirectory. Inside the rails subdirectory, I can create symbolic links to my rails applications located in my projects directory. This way, rails configuration is not exposed from Apache.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>wwwroot
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> rails
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>travelsiteph<span style="color: #000000; font-weight: bold;">/</span>public travelsiteph
&nbsp;
$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-la</span>
total <span style="color: #000000;">8</span>
drwxr-xr-x   <span style="color: #000000;">3</span> rupert  admin   <span style="color: #000000;">102</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">14</span>:09 .
drwxrwxr-x  <span style="color: #000000;">60</span> root    admin  <span style="color: #000000;">2040</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">14</span>:08 ..
lrwxr-xr-x   <span style="color: #000000;">1</span> rupert  admin    <span style="color: #000000;">42</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">14</span>:09 travelsiteph -<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>travelsiteph<span style="color: #000000; font-weight: bold;">/</span>public</pre></div></div>

<p>5. Restart Apache to take the new configuration</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>StartupItems<span style="color: #000000; font-weight: bold;">/</span>Apache2<span style="color: #000000; font-weight: bold;">/</span>Apache2 restart</pre></div></div>

<p>6. Open http://127.0.0.1/rails/travelsiteph/</p>
<p><em>But for development purposes, it is better to use http://127.0.0.1:3000/ to see immediately any changes in code.</em> </p>
<p><img src="/wordpress/wp-content/uploads/2009/09/rails.png" alt="rails.png" border="0" width="150" height="108" /></p>
<p><strong>Part 2: Rails Development</strong><br />
MySQL Prerequisites:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">GRANT</span> <span style="color: #993333; font-weight: bold;">ALL</span> PRIVILEGES <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">*.*</span> <span style="color: #993333; font-weight: bold;">TO</span> rupert@<span style="color: #ff0000;">'%'</span> <span style="color: #993333; font-weight: bold;">IDENTIFIED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'*************'</span> <span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #993333; font-weight: bold;">GRANT</span> <span style="color: #993333; font-weight: bold;">OPTION</span>;
$ mysql <span style="color: #66cc66;">-</span>u rupert <span style="color: #66cc66;">-</span>p</pre></div></div>

<p>1. Create three databases:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> travelsiteph_development;
Query OK<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span> row affected <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.00</span> sec<span style="color: #66cc66;">&#41;</span>
&nbsp;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> travelsiteph_test;
Query OK<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span> row affected <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.00</span> sec<span style="color: #66cc66;">&#41;</span>
&nbsp;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> travelsiteph_deployment;
Query OK<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span> row affected <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.00</span> sec<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>2. Launch Textmate</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>travelsiteph
mate .</pre></div></div>

<p>3. Edit database.yml</p>

<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;">development:
  adapter: mysql
  database: travelsiteph_development
  username: root
  password: xxxxxxx
  host: localhost
&nbsp;
test:
  adapter: mysql
  database: travelsiteph_test
  username: root
  password: xxxxxxx
  host: localhost
&nbsp;
production:
  adapter: mysql
  database: travelsiteph_deployment
  username: root
  password: xxxxxxx
  host: localhost</pre></div></div>

<p>4. Generate a Poi model. <em>The model should be capitalized and singular.</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ ruby script<span style="color: #000000; font-weight: bold;">/</span>generate model Poi
      exists  app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>
      exists  test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>
      exists  test<span style="color: #000000; font-weight: bold;">/</span>fixtures<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>poi.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>poi_test.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>fixtures<span style="color: #000000; font-weight: bold;">/</span>pois.yml
      create  db<span style="color: #000000; font-weight: bold;">/</span>migrate
      create  db<span style="color: #000000; font-weight: bold;">/</span>migrate<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">20090902111538</span>_create_pois.rb</pre></div></div>

<p>5. Now let&#8217;s create the database table for Poi using migrations.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Poi <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>
    create_table <span style="color:#ff3333; font-weight:bold;">:pois</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:poi_id</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:full_address</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:location</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:get_there</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:short_description</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:full_description</span>, <span style="color:#ff3333; font-weight:bold;">:text</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:other_info</span>, <span style="color:#ff3333; font-weight:bold;">:text</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:tel_no</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:fax_no</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:mobile_no</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:email</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:website</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:other_contact_details</span>, <span style="color:#ff3333; font-weight:bold;">:text</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:longitude</span>, <span style="color:#ff3333; font-weight:bold;">:decimal</span>, <span style="color:#ff3333; font-weight:bold;">:precision</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">10</span>, <span style="color:#ff3333; font-weight:bold;">:scale</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">7</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:latitude</span>, <span style="color:#ff3333; font-weight:bold;">:decimal</span>, <span style="color:#ff3333; font-weight:bold;">:precision</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">10</span>, <span style="color:#ff3333; font-weight:bold;">:scale</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">7</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:created_at</span>, <span style="color:#ff3333; font-weight:bold;">:timestamp</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:updated_at</span>, <span style="color:#ff3333; font-weight:bold;">:timestamp</span>
      t.<span style="color:#9900CC;">timestamps</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">down</span>
    drop_table <span style="color:#ff3333; font-weight:bold;">:pois</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ rake db:migrate
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>travelsiteph<span style="color: #7a0874; font-weight: bold;">&#41;</span>
==  CreatePois: migrating =========================================
<span style="color: #660033;">--</span> create_table<span style="color: #7a0874; font-weight: bold;">&#40;</span>:point_of_interests, <span style="color: #7a0874; font-weight: bold;">&#123;</span>:<span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">id</span></span>=<span style="color: #000000; font-weight: bold;">&gt;</span>:poi_id<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
   -<span style="color: #000000; font-weight: bold;">&gt;</span> 0.0353s
==  CreatePois: migrated <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.0362s<span style="color: #7a0874; font-weight: bold;">&#41;</span> ================================</pre></div></div>

<p>6. Generate a Poi controller.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ script<span style="color: #000000; font-weight: bold;">/</span>generate controller Poi
      exists  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>
      exists  app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>poi
      create  test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>
      create  test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>poi_controller.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>poi_controller_test.rb
      create  app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>poi_helper.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>poi_helper_test.rb</pre></div></div>

<p>7. Add a <em>list</em> function to Poi Controller</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> PoiController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
  <span style="color:#9966CC; font-weight:bold;">def</span> list
    <span style="color:#0066ff; font-weight:bold;">@pois</span> = Poi.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>8. Lets test. Open a browser and point to http://127.0.0.1:3000/travelsiteph/poi/list</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">$ruby</span> script<span style="color: #000000; font-weight: bold;">/</span>server</pre></div></div>

<p>9. Now create the view <em>list.rhtml</em> in <em>views/poi/</em></p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@pois</span>.<span style="color:#9900CC;">blank</span>? <span style="color:#006600; font-weight:bold;">%&gt;</span>
&nbsp;
	&lt;p&gt;There are currently no pois in the system. &lt;/p&gt;
&nbsp;
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
&nbsp;
	&lt;p&gt;These are the pois in the system: &lt;/p&gt;
&nbsp;
	&lt;ul&gt;
		<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#0066ff; font-weight:bold;">@pois</span>.<span style="color:#5A0A0A; font-weight:bold;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>poi<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
			&lt;li&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">link_to</span> poi.<span style="color:#9900CC;">name</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:action <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'show'</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> poi.<span style="color:#9900CC;">id</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">-%&gt;</span>&lt;/li&gt;
		<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
	&lt;/ul&gt;
&nbsp;
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p><strong>Part 3: Deploying</strong><br />
1. set RAILS_ENV to production</p>
<pre>export RAILS_ENV=production</pre>
<p>2. Make sure to populate the database in production mode, run rake db:migrate</p>
<p>3. Capistrano</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">set <span style="color:#ff3333; font-weight:bold;">:port</span>, <span style="color:#006666;">2210</span>
set <span style="color:#ff3333; font-weight:bold;">:application</span>, <span style="color:#996600;">&quot;halalan2010&quot;</span>
<span style="color:#008000; font-style:italic;">#set :repository,  &quot;svn+ssh://2rmobile.com/data/repos/web/rails/halalan2010/&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:repository</span>,  <span style="color:#996600;">&quot;http://2rmobile.com/repos/web/rails/halalan2010/&quot;</span>
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:scm</span>, <span style="color:#ff3333; font-weight:bold;">:subversion</span>
set <span style="color:#ff3333; font-weight:bold;">:scm_username</span>, <span style="color:#996600;">'rupert'</span>
set <span style="color:#ff3333; font-weight:bold;">:scm_password</span>, <span style="color:#CC0066; font-weight:bold;">proc</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#6666ff; font-weight:bold;">Capistrano::CLI</span>.<span style="color:#9900CC;">password_prompt</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'SVN pass:'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#008000; font-style:italic;"># Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`</span>
&nbsp;
role <span style="color:#ff3333; font-weight:bold;">:web</span>, <span style="color:#996600;">&quot;2rmobile.com&quot;</span> <span style="color:#008000; font-style:italic;"># IP Your HTTP server, Apache/etc</span>
role <span style="color:#ff3333; font-weight:bold;">:app</span>, <span style="color:#996600;">&quot;2rmobile.com&quot;</span> <span style="color:#008000; font-style:italic;"># This may be the same as your `Web` server</span>
role <span style="color:#ff3333; font-weight:bold;">:db</span>,  <span style="color:#996600;">&quot;2rmobile.com&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:primary</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#008000; font-style:italic;"># This is where Rails migrations will run</span>
<span style="color:#008000; font-style:italic;">#role :db,  &quot;your slave db-server here&quot;</span>
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:user</span>,  <span style="color:#996600;">&quot;rupert&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:runner</span>, <span style="color:#996600;">&quot;rupert&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:deploy_to</span>, <span style="color:#996600;">&quot;/opt/rails/#{application}&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># If you are using Passenger mod_rails uncomment this:</span>
<span style="color:#008000; font-style:italic;"># if you're still using the script/reapear helper you will need</span>
<span style="color:#008000; font-style:italic;"># these http://github.com/rails/irs_process_scripts</span>
&nbsp;
namespace <span style="color:#ff3333; font-weight:bold;">:deploy</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  task <span style="color:#ff3333; font-weight:bold;">:start</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;/etc/init.d/apache2 start&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  task <span style="color:#ff3333; font-weight:bold;">:stop</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;/etc/init.d/apache2 stop&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  task <span style="color:#ff3333; font-weight:bold;">:restart</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span>, <span style="color:#ff3333; font-weight:bold;">:except</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:no_release</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
     run <span style="color:#996600;">&quot;#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  task <span style="color:#ff3333; font-weight:bold;">:production</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;export RAILS_ENV=production&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
namespace <span style="color:#ff3333; font-weight:bold;">:db</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  task <span style="color:#ff3333; font-weight:bold;">:seed</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;cd #{deploy_to}/current &amp;&amp; RAILS_ENV=production rake db:seed&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  task <span style="color:#ff3333; font-weight:bold;">:populate</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;cd #{deploy_to}/current &amp;&amp; RAILS_ENV=production rake db:populate&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Capistrano commands I normally use:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">#on local
#cap deploy:setup
&nbsp;
#on remote and change owner and permissions of project
sudo chown -Rf rupert:root halalan2010
&nbsp;
#on local
#cap deploy
#cap db:seed
#cap db:populate</pre></div></div>

<p><strong>Part 4: Miscellaneous</strong></p>
<p><strong>1. Get a description or rake commands</strong></p>
<pre>rake -D db</pre>
<p><strong>2. How to populate the database in production mode?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="console" style="font-family:monospace;">rupert:halalan2010 rupert$ export RAILS_ENV=production
rupert:halalan2010 rupert$ rake db:migrate
(in /Users/rupert/projects/rails/halalan2010)
==  CreateDatabase: migrating =================================================
-- create_table(:candidates)
   -&gt; 0.0036s
-- create_table(:voters)
   -&gt; 0.0031s
-- create_table(:votes)
   -&gt; 0.0027s
==  CreateDatabase: migrated (0.0100s) ========================================</pre></div></div>

<p><a href="http://blog.airbladesoftware.com/2009/4/10/avoid-typing-rails_env-all-the-time">http://blog.airbladesoftware.com/2009/4/10/avoid-typing-rails_env-all-the-time</a></p>
<p><strong>3. Uninstall specific gem version</strong></p>
<pre>
gem uninstall activesupport -v 2.2.2
</pre>
<p><strong>4 Add a source to gem</strong></p>
<pre>
rupert:rails rupert$ sudo gem sources -a http://gems.github.com
http://gems.github.com added to sources
</pre>
<p><strong>5. Adding a rails project in svn</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#create a remote dir</span>
<span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.2rmobile.com<span style="color: #000000; font-weight: bold;">/</span>repos<span style="color: #000000; font-weight: bold;">/</span>web<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>virginmobilechecker
&nbsp;
<span style="color: #666666; font-style: italic;">#checkout and copy all files</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>rails
<span style="color: #c20cb9; font-weight: bold;">mv</span> virginmobilechecker virginmobilechecker_old
<span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> <span style="color: #ff0000;">&quot;svn+ssh://2rmobile.com/data/repos/web/rails/virginmobilechecker&quot;</span> virginmobilechecker
<span style="color: #c20cb9; font-weight: bold;">mv</span> virginmobilechecker_old<span style="color: #000000; font-weight: bold;">/*</span> virginmobilechecker<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> virginmobilechecker
<span style="color: #c20cb9; font-weight: bold;">svn</span> add <span style="color: #000000; font-weight: bold;">*</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#ignoring log files</span>
<span style="color: #c20cb9; font-weight: bold;">svn</span> revert log<span style="color: #000000; font-weight: bold;">/*</span>
<span style="color: #c20cb9; font-weight: bold;">svn</span> propset <span style="color: #c20cb9; font-weight: bold;">svn</span>:ignore <span style="color: #ff0000;">&quot;*.log&quot;</span> log
<span style="color: #c20cb9; font-weight: bold;">svn</span> propset <span style="color: #c20cb9; font-weight: bold;">svn</span>:ignore <span style="color: #ff0000;">&quot;*&quot;</span> tmp
<span style="color: #c20cb9; font-weight: bold;">svn</span> propset <span style="color: #c20cb9; font-weight: bold;">svn</span>:ignore <span style="color: #ff0000;">&quot;*&quot;</span> doc
&nbsp;
<span style="color: #666666; font-style: italic;">#commit the files</span>
<span style="color: #c20cb9; font-weight: bold;">svn</span> commit <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;first commit&quot;</span> <span style="color: #000000; font-weight: bold;">*</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2010/02/ruby-on-rails-quickstart-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Note #20:Integrating Mapserver/TileCache to RouteMe</title>
		<link>/wordpress/2010/01/iphone-note-20integrating-mapservertilecache-to-routeme/</link>
		<comments>/wordpress/2010/01/iphone-note-20integrating-mapservertilecache-to-routeme/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 01:37:57 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mapserver]]></category>
		<category><![CDATA[tilecache]]></category>

		<guid isPermaLink="false">/wordpress/?p=700</guid>
		<description><![CDATA[Below is a summary of how I was able to implement Mapserver, TileCache and Route-Me iPhone Mapping Framework. 1. Assuming you have a working Mapserver/TileCache setup. Take note of the ff parameters: resolution and bbox. Below is my tilecache.cfg: 61 [mapserver_australia_3857] 62 type=MapServerLayer 63 mapfile=/Users/rupert/projects/pelicancorp/DMOB/trunk/map/australia_3857.map 64 layers=all 65 extension=jpg 66 bbox=-20037508.34, -20037508.34, 20037508.34, 20037508.34 68]]></description>
			<content:encoded><![CDATA[<p>Below is a summary of how I was able to implement Mapserver, TileCache and Route-Me iPhone Mapping Framework. </p>
<p>1.  Assuming you have a <strong>working</strong> Mapserver/TileCache setup. Take note of the ff parameters: resolution and bbox. Below is my tilecache.cfg:</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;"> 61 [mapserver_australia_3857]
 62 type=MapServerLayer
 63 mapfile=/Users/rupert/projects/pelicancorp/DMOB/trunk/map/australia_3857.map
 64 layers=all
 65 extension=jpg
 66 bbox=-20037508.34, -20037508.34, 20037508.34, 20037508.34
 68 maxResolution=156543.033928041
 70 levels=20
 71 srs=EPSG:3857
 72 tms_type=google
 73 extent_type=loose
 74 spherical_mercator=true</pre></div></div>

<p>2. Grab the RMGenericMercatorWMSSource from <a href="http://groups.google.com/group/route-me-map/browse_thread/thread/b58fa1d20cf15823/e30c42d9c90a8170?lnk=gst&#038;q=Generic#e30c42d9c90a8170">http://groups.google.com/group/route-me-map/browse_thread/thread/b58fa1d20cf15823/e30c42d9c90a8170?lnk=gst&#038;q=Generic#e30c42d9c90a8170</a></p>
<p>3. By default without any changes, the RMGenericMercatorWMSSource could display Mapserver WMS Tiles. This is possible by passing an NSDictionary *parameters, which contains arrayValues and arrayKeys for creating an http 256&#215;256 image request to the http://127.0.0.1/cgi-bin/mapserv binary.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//This would request to http://127.0.0.1/cgi-bin/mapserv</span>
<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>arrayValues <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;/path-to/australia_3857.map&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;all&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;png&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;EPSG:3857&quot;</span>,<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>arrayKeys <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MAP&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;LAYERS&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;FORMAT&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;SRS&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>wmsParameters <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDictionary</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span> arrayValues forKeys<span style="color: #002200;">:</span>arrayKeys <span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Resulting http requests to the mapserv binary:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">http://192.168.1.193:81/tilecache/tilecache.py?LAYERS=australia_3857&amp;SRS=EPSG:3857&amp;REQUEST=GetMap&amp;SERVICE=WMS&amp;STYLES=&amp;EXCEPTIONS=application%2Fvnd.ogc.se_inimage&amp;FORMAT=png&amp;VERSION=1.1.1&amp;WIDTH=256&amp;HEIGHT=256&amp;BBOX=16828376.000000,-4006523.000000,16833268.000000,-4001631.000000</pre></div></div>

<p>Note that the bbox values does not contain decimal places. Nevertheless, it still works on Mapserver.</p>
<p>4. Now, assuming we have a valid tilecache running. And it is tested from browser, i.e http://127.0.0.1/map/tilecache_3857.html, open up firebug to see the requests. Below is a sample&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">http://192.168.1.193:81/tilecache/tilecache.py?LAYERS=australia_3857&amp;FORMAT=jpg&amp;SERVICE=WMS&amp;VERSION=1.1.1&amp;REQUEST=GetMap&amp;STYLES=&amp;EXCEPTIONS=application%2Fvnd.ogc.se_inimage&amp;SRS=EPSG%3A3857&amp;BBOX=16123932.497377,-4539747.9811239,16143500.376618,-4520180.1018829&amp;WIDTH=256&amp;HEIGHT=256</pre></div></div>

<p>But it seems, route-me is not supplying the bbox values accurately, as the decimal values is truncated (BBOX=16828376.000000,-4006523.000000,16833268.000000,-4001631.000000) from our previous request(3). </p>
<p>After changing the wmsParameter values to create a tilecache request, I noticed that route-me is not displaying the tiles correctly.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//Testing for Windows:TileCache - ?</span>
<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>arrayValues <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;australia_3857&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;png&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;EPSG:3857&quot;</span>,<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//for WIndows</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//TileCache URL Parameters:</span>
<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>arrayKeys <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;LAYERS&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;FORMAT&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;SRS&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>5. The workaround is to use &#8220;double&#8221; instead of &#8220;floats&#8221; in the RMGenericMercatorWMSSource. You can download the zip from <a href="/wordpress/wp-content/uploads/2010/01/RMGenericMercatorWMSSource.zip" title="RMGenericMercatorWMSSource.zip">RMGenericMercatorWMSSource.zip</a>. I have modified &#8220;initialResolution&#8221; and &#8220;originShift&#8221; to both use <em>&#8220;double&#8221;</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">typedef</span> <span style="color: #a61390;">struct</span> <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">double</span> x;
	<span style="color: #a61390;">double</span> y;
<span style="color: #002200;">&#125;</span> CGDoublePoint;
&nbsp;
<span style="color: #a61390;">typedef</span> <span style="color: #a61390;">struct</span> <span style="color: #002200;">&#123;</span> 
	CGDoublePoint ul; 
	CGDoublePoint lr; 
<span style="color: #002200;">&#125;</span> CGXYRect;</pre></div></div>

<p>Afterwards, I copied the maxResolution and bbox (tilecache) and specified it for the initialResoultion and originShift respectively.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;RMGenericMercatorWMSSource.h&quot;</span>
&nbsp;
CGFloat DegreesToRadians<span style="color: #002200;">&#40;</span>CGFloat degrees<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><span style="color: #a61390;">return</span> degrees <span style="color: #002200;">*</span> M_PI <span style="color: #002200;">/</span> <span style="color: #2400d9;">180</span>;<span style="color: #002200;">&#125;</span>; 
CGFloat RadiansToDegrees<span style="color: #002200;">&#40;</span>CGFloat radians<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><span style="color: #a61390;">return</span> radians <span style="color: #002200;">*</span> <span style="color: #2400d9;">180</span><span style="color: #002200;">/</span> M_PI;<span style="color: #002200;">&#125;</span>; 
&nbsp;
<span style="color: #a61390;">@implementation</span> RMGenericMercatorWMSSource
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> initWithBaseUrl<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>baseUrl parameters<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>params
<span style="color: #002200;">&#123;</span> 
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span><span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> 
		<span style="color: #a61390;">return</span> <span style="color: #a61390;">nil</span>; 
&nbsp;
	<span style="color: #11740a; font-style: italic;">// 156543.03392804062 for sideLength 256 pixels </span>
	<span style="color: #11740a; font-style: italic;">// initialResolution = 2 * M_PI * 6378137 / [self tileSideLength];</span>
	<span style="color: #11740a; font-style: italic;">// specify here whatever the resolution is from tilecache.</span>
	initialResolution <span style="color: #002200;">=</span> <span style="color: #2400d9;">156543.033928041</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// 20037508.342789244 </span>
	<span style="color: #11740a; font-style: italic;">//originShift = 2 * M_PI * 6378137 / 2;</span>
	<span style="color: #11740a; font-style: italic;">//originShift = 20037508.342789244f;</span>
	<span style="color: #11740a; font-style: italic;">// specify here whatever the bbox is from tilecache.</span>
	originShift <span style="color: #002200;">=</span> <span style="color: #2400d9;">20037508.32</span>;
&nbsp;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;test initialResolution:%f originShift:%f&quot;</span>, initialResolution, originShift<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// setup default parameters</span>
	<span style="color: #11740a; font-style: italic;">// use official EPSG:3857 by default, user can override to 900913 if needed.</span>
	wmsParameters <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableDictionary</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;EPSG:3857&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;image/png&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;GetMap&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;1.1.1&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;WMS&quot;</span>,<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span> 
											  forKeys<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;SRS&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;FORMAT&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;REQUEST&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;VERSION&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;SERVICE&quot;</span>,<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>wmsParameters addEntriesFromDictionary<span style="color: #002200;">:</span>params<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// build WMS request URL template</span>
	urlTemplate <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithString<span style="color: #002200;">:</span>baseUrl<span style="color: #002200;">&#93;</span>;
	<span style="color: #400080;">NSEnumerator</span> <span style="color: #002200;">*</span>e <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>wmsParameters keyEnumerator<span style="color: #002200;">&#93;</span>;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>key;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>delimiter <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&quot;</span>;
	<span style="color: #a61390;">while</span> <span style="color: #002200;">&#40;</span>key <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>e nextObject<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		urlTemplate <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>urlTemplate stringByAppendingFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%@%@=%@&quot;</span>,
					   delimiter,
					   <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>key uppercaseString<span style="color: #002200;">&#93;</span> stringByAddingPercentEscapesUsingEncoding<span style="color: #002200;">:</span>NSASCIIStringEncoding<span style="color: #002200;">&#93;</span>, 
					   <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>wmsParameters objectForKey<span style="color: #002200;">:</span>key<span style="color: #002200;">&#93;</span> stringByAddingPercentEscapesUsingEncoding<span style="color: #002200;">:</span>NSASCIIStringEncoding<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
		delimiter <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&amp;&quot;</span>;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">int</span> sideLength <span style="color: #002200;">=</span>  <span style="color: #002200;">&#91;</span>self tileSideLength<span style="color: #002200;">&#93;</span>;
	urlTemplate <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>urlTemplate stringByAppendingFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&amp;WIDTH=%d&amp;HEIGHT=%d&quot;</span>,sideLength,sideLength<span style="color: #002200;">&#93;</span> retain<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// implement in subclass?</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> uniqueTilecacheKey
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;AbstractMercatorWMSSource&quot;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>shortName
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Generic WMS Source&quot;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>longDescription
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Generic WMS Source&quot;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>shortAttribution
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Generic WMS Source&quot;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>longAttribution
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Generic WMS Source&quot;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span> minZoom
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> 1.0f;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span> maxZoom
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> 19.0f;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// Converts given lat/lon in WGS84 Datum to XY in Spherical Mercator EPSG:3857 </span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>CGPoint<span style="color: #002200;">&#41;</span> LatLonToMeters<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>CLLocationCoordinate2D<span style="color: #002200;">&#41;</span> latlon 
<span style="color: #002200;">&#123;</span> 
	CGPoint meters; 
	meters.x <span style="color: #002200;">=</span> latlon.longitude <span style="color: #002200;">*</span> originShift <span style="color: #002200;">/</span> <span style="color: #2400d9;">180</span>; 
	meters.y <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">log</span><span style="color: #002200;">&#40;</span> <span style="color: #a61390;">tan</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span><span style="color: #2400d9;">90.0</span> <span style="color: #002200;">+</span> latlon.latitude<span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> M_PI <span style="color: #002200;">/</span> <span style="color: #2400d9;">360.0</span> <span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">/</span> <span style="color: #002200;">&#40;</span>M_PI <span style="color: #002200;">/</span> <span style="color: #2400d9;">180.0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> originShift <span style="color: #002200;">/</span> <span style="color: #2400d9;">180</span>; 
	<span style="color: #a61390;">return</span> meters; 
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//Converts XY point from Spherical Mercator EPSG:3857 to lat/lon in WGS84 Datum </span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>CLLocationCoordinate2D<span style="color: #002200;">&#41;</span> MetersToLatLon<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>CGPoint<span style="color: #002200;">&#41;</span> meters 
<span style="color: #002200;">&#123;</span> 
	CLLocationCoordinate2D latlon; 
	latlon.longitude <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>meters.x <span style="color: #002200;">/</span> originShift<span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> <span style="color: #2400d9;">180.0</span>; 
	latlon.latitude <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>meters.y <span style="color: #002200;">/</span> originShift<span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> <span style="color: #2400d9;">180.0</span>; 
	<span style="color: #11740a; font-style: italic;">//latlon.latitude = - 180 / M_PI * (2 * atan( exp( latlon.latitude * M_PI / 180.0)) - M_PI / 2.0); </span>
	latlon.latitude <span style="color: #002200;">=</span> <span style="color: #2400d9;">180</span> <span style="color: #002200;">/</span> M_PI <span style="color: #002200;">*</span> <span style="color: #002200;">&#40;</span><span style="color: #2400d9;">2</span> <span style="color: #002200;">*</span> <span style="color: #a61390;">atan</span><span style="color: #002200;">&#40;</span> <span style="color: #a61390;">exp</span><span style="color: #002200;">&#40;</span> latlon.latitude <span style="color: #002200;">*</span> M_PI <span style="color: #002200;">/</span> <span style="color: #2400d9;">180.0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">-</span> M_PI <span style="color: #002200;">/</span> <span style="color: #2400d9;">2.0</span><span style="color: #002200;">&#41;</span>; 
	<span style="color: #a61390;">return</span> latlon; 
<span style="color: #002200;">&#125;</span> 
&nbsp;
<span style="color: #11740a; font-style: italic;">// Converts pixel coordinates in given zoom level of pyramid to EPSG:3857 </span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>CGDoublePoint<span style="color: #002200;">&#41;</span> PixelsToMeters<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> px PixelY<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>py atZoom<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>zoom 
<span style="color: #002200;">&#123;</span> 
	<span style="color: #a61390;">double</span> resolution <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self ResolutionAtZoom<span style="color: #002200;">:</span> zoom<span style="color: #002200;">&#93;</span>; 
	CGDoublePoint meters; 
	<span style="color: #a61390;">double</span> x <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>px <span style="color: #002200;">*</span> resolution <span style="color: #002200;">-</span> originShift<span style="color: #002200;">&#41;</span>; 
	<span style="color: #a61390;">double</span> y <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>py <span style="color: #002200;">*</span> resolution <span style="color: #002200;">-</span> originShift<span style="color: #002200;">&#41;</span>; 
&nbsp;
	meters.x <span style="color: #002200;">=</span> x;
	meters.y <span style="color: #002200;">=</span> y;
&nbsp;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;px: %d py: %d resolution: %f originShift: %f x: %f y: %f&quot;</span>, px, py, resolution, originShift, x, y<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #a61390;">return</span> meters; 
<span style="color: #002200;">&#125;</span> 
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> tileURL<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>RMTile<span style="color: #002200;">&#41;</span> tile 
<span style="color: #002200;">&#123;</span> 
	<span style="color: #11740a; font-style: italic;">//RMLatLongBounds tileBounds = [self TileLatLonBounds:tile];</span>
	<span style="color: #11740a; font-style: italic;">// Get BBOX coordinates in meters</span>
	CGXYRect tileBounds <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self TileBounds<span style="color: #002200;">:</span>tile<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>url <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>urlTemplate stringByAppendingFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&amp;BBOX=%f,%f,%f,%f&quot;</span>,
					 tileBounds.ul.x,
					 tileBounds.lr.y,
					 tileBounds.lr.x,
					 tileBounds.ul.y<span style="color: #002200;">&#93;</span>;
&nbsp;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Tile %d,%d,%d yields %@&quot;</span>,tile.zoom, tile.x, tile.y, url<span style="color: #002200;">&#41;</span>; 
&nbsp;
	<span style="color: #a61390;">return</span> url; 
<span style="color: #002200;">&#125;</span> 
&nbsp;
&nbsp;
<span style="color: #11740a; font-style: italic;">//Returns bounds of the given tile in EPSG:3857 coordinates </span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>CGXYRect<span style="color: #002200;">&#41;</span>  TileBounds<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>RMTile<span style="color: #002200;">&#41;</span> tile 
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">int</span> sideLength <span style="color: #002200;">=</span>  <span style="color: #002200;">&#91;</span>self tileSideLength<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #a61390;">int</span> zoom <span style="color: #002200;">=</span> tile.zoom;
	<span style="color: #a61390;">long</span> twoToZoom <span style="color: #002200;">=</span> <span style="color: #a61390;">pow</span><span style="color: #002200;">&#40;</span><span style="color: #2400d9;">2</span>,zoom<span style="color: #002200;">&#41;</span>;
	CGXYRect tileBounds; 
	tileBounds.ul <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self PixelsToMeters<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>tile.x <span style="color: #002200;">*</span> sideLength<span style="color: #002200;">&#41;</span> 
								  PixelY<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>twoToZoom<span style="color: #002200;">-</span>tile.y<span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> sideLength<span style="color: #002200;">&#41;</span> 
								  atZoom<span style="color: #002200;">:</span> zoom <span style="color: #002200;">&#93;</span>; 
	tileBounds.lr <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self PixelsToMeters<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>tile.x<span style="color: #002200;">+</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> sideLength<span style="color: #002200;">&#41;</span> 
								  PixelY<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>twoToZoom<span style="color: #002200;">-</span>tile.y<span style="color: #002200;">-</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> sideLength<span style="color: #002200;">&#41;</span> 
								  atZoom<span style="color: #002200;">:</span> zoom<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">return</span> tileBounds; 
<span style="color: #002200;">&#125;</span> 
&nbsp;
<span style="color: #11740a; font-style: italic;">//Resolution (meters/pixel) for given zoom level (measured at Equator) </span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">double</span><span style="color: #002200;">&#41;</span> ResolutionAtZoom <span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> zoom 
<span style="color: #002200;">&#123;</span> 
	<span style="color: #a61390;">return</span> initialResolution <span style="color: #002200;">/</span> <span style="color: #a61390;">pow</span><span style="color: #002200;">&#40;</span><span style="color: #2400d9;">2</span>,zoom<span style="color: #002200;">&#41;</span>; 
<span style="color: #002200;">&#125;</span> 
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>6. Download <a href="/wordpress/wp-content/uploads/2010/01/TileCache_RouteMe.zip" title="TileCache_RouteMe.zip">TileCache_RouteMe.zip</a> Note: You need a valid mapserver and tilecache running.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2010/01/iphone-note-20integrating-mapservertilecache-to-routeme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Note #19: Route-Me: Opensource mapping for the iphone</title>
		<link>/wordpress/2009/12/iphone-dev-note-19-route-me-opensource-mapping-for-the-iphone/</link>
		<comments>/wordpress/2009/12/iphone-dev-note-19-route-me-opensource-mapping-for-the-iphone/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 05:34:51 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=671</guid>
		<description><![CDATA[Route-Me is an opensource mapping api similar to the MapKit.framework. The main project resides in googlecode (http://code.google.com/p/route-me/). Part 1: Making the Sample Apps work. 1. Download the code from svn. svn co http://route-me.googlecode.com/svn/trunk/ route-me 2. In the route-me directory, you would have 3 directories: - MapView &#8211; this contains the mapping framework - Proj4 &#8211;]]></description>
			<content:encoded><![CDATA[<p>Route-Me is an opensource mapping api similar to the MapKit.framework. The main project resides in googlecode (<a href="http://code.google.com/p/route-me/">http://code.google.com/p/route-me/</a>).</p>
<h3>Part 1: Making the Sample Apps work.</h3>
<p>1. Download the code from svn.<br />
svn co http://route-me.googlecode.com/svn/trunk/ route-me</p>
<p>2. In the route-me directory, you would have 3 directories:<br />
- MapView &#8211; this contains the mapping framework<br />
- Proj4   &#8211; projection library.<br />
- samples</p>
<p>3. Build MapView. I encountered some problems here, particularly this specific <a href="http://code.google.com/p/route-me/issues/detail?id=114">issue: Cannot build on 3.1 using iphone simulator</a>. </p>
<p><strong>How to make the build?</strong> Now, at the time of this writing, I have XCode3.1.4 and iPhone 3.0, 3.1, 3.1.2. Edit the project settings so that the &#8220;build&#8221; and &#8220;release&#8221; will point to use 3.0.  If you encounter a problem, it is best to &#8220;Clean All&#8221;, remove the build directory, then &#8220;Build&#8221; again. To verfiy if you have a successful build, notice that libMapView.a was created.</p>
<p><img src="/wordpress/wp-content/uploads/2009/12/routeme-libMapView.png" alt="routeme-libMapView.png" border="0" width="274" height="218" /></p>
<p>Note: Notice here that I have <strong>libMapView.a</strong> both in <em>Debug-iphoneos/</em> and <em>Debug-iphonesimulator/</em></p>
<p>No need to build Proj4 as long as it is sitting on the same directory where MapView is. </p>
<p>4. To test route-me, we can study from the samples directory. Let&#8217;s build samples/SampleMap. Notice that SampleMap has a reference to MapView.xcodeproj. </p>
<p><img src="/wordpress/wp-content/uploads/2009/12/routeme-samplemap.png" alt="routeme-samplemap.png" border="0" width="179" height="102" /></p>
<p>Similarly, we can build this using 3.0 both in the simulator and device.</p>
<p><img src="/wordpress/wp-content/uploads/2009/12/routeme-samplemap-ok.jpg" alt="routeme-samplemap-ok.jpg" border="0" width="161" height="243" /></p>
<h3>Part 2: Integrating with your own project.</h3>
<p>Reference: <a href="http://code.google.com/p/route-me/wiki/EmbeddingGuide">http://code.google.com/p/route-me/wiki/EmbeddingGuide</a></p>
<p>1. Create a view-based project: MyRMSampleMap. </p>
<p>2. Project -> &#8220;Add To Project&#8221;. Make the reference type as &#8220;Relative to Project&#8221;.</p>
<p><img src="/wordpress/wp-content/uploads/2009/12/routeme-referencing-mapview.jpg" alt="routeme-referencing-mapview.jpg" border="0" width="250" height="233" /></p>
<p>3. Configure your project to have a direct dependency with MapView.xcodeproj. Follow the instructions exactly as stated from the EmbeddingGuide.</p>
<p><img src="/wordpress/wp-content/uploads/2009/12/routeme-ref-dd.jpg" alt="routeme-ref-dd.jpg" border="0" width="275" height="417" /></p>
<blockquote><p>Click on the &#8220;Build&#8221; tab in your target&#8217;s info window.</p>
<p>Change the Configuration popup to read &#8220;All Configurations&#8221;, so that your changes can be made just once.</p>
<p>Find &#8220;Header Search Paths&#8221; under &#8220;Search Paths&#8221; (shortcut: type &#8220;header&#8221; in the search box at upper right of the target info window). Double-click on the &#8216;Header Search Paths&#8217; text and add the path to the MapView directory contained in the route-me project located on your file system. (Note that if there are any spaces in the path, enclose the entire entry with &#8220;&#8221;. If the MapView project folder is placed next to your project&#8217;s project folder on the file system, you would have the following in the path: &#8220;../MapView&#8221;.</p>
<p>Check the &#8216;Recursive&#8217; box and click Ok. </p></blockquote>
<p><img src="/wordpress/wp-content/uploads/2009/12/routeme-searchpaths.jpg" alt="routeme-searchpaths.jpg" border="0" width="400" height="205" /></p>
<p>4. Make a test &#8220;Build&#8221;.</p>
<p>5. Add a reference to:<br />
- QuartzCore.framework<br />
- libsqlite3.dylib</p>
<p>6. Let&#8217;s add our mapview in the interface: MyRMSampleMapViewController.h</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span>
<span style="color: #6e371a;">#import &quot;RMMapView.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> MyRMSampleMapViewController <span style="color: #002200;">:</span> UIViewController <span style="color: #002200;">&#123;</span>
	RMMapView <span style="color: #002200;">*</span>mapview;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> RMMapView <span style="color: #002200;">*</span>mapview;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>7. In the implementation, add this snippet.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@synthesize</span> mapview;
...
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>viewWillAppear<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>animated<span style="color: #002200;">&#123;</span>
	mapview <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>RMMapView alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span>0.0f, 0.0f, 320.0f, 460.0f<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>mapview setBackgroundColor<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIColor blackColor<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>self.view addSubview<span style="color: #002200;">:</span>mapview<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Download: <a href="/wordpress/wp-content/uploads/2009/12/MyRMSampleMap.zip" title="MyRMSampleMap.zip">MyRMSampleMap.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/12/iphone-dev-note-19-route-me-opensource-mapping-for-the-iphone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Note #18: Integrating Ads (AdMob) on your iPhone App</title>
		<link>/wordpress/2009/12/iphone-dev-note-18-integrating-ads-admob-on-your-iphone-app/</link>
		<comments>/wordpress/2009/12/iphone-dev-note-18-integrating-ads-admob-on-your-iphone-app/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 00:46:39 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=657</guid>
		<description><![CDATA[Basic Info What is common with these ad platforms? Each application is offered a unique id which needs to be specified during development. What is publishing? Publishing allows the developer to display (publish) ads on the native application. What is CPM? Impressions per thousand. Normally ad networks pays $1 for every 1000 CPM. So you]]></description>
			<content:encoded><![CDATA[<h2>Basic Info</h2>
<p><strong>What is common with these ad platforms?</strong><br />
Each application is offered a unique id which needs to be specified during development.</p>
<p><strong>What is publishing?</strong><br />
Publishing allows the developer to display (<em>publish</em>) ads on the native application.</p>
<p><strong>What is CPM?</strong><br />
Impressions per thousand. Normally ad networks pays $1 for every 1000 CPM. So you need 1000 page views (not clicks) to earn a buck.</p>
<p><strong>What is the fillrate?</strong><br />
The percentage of impressions served based on total requests for ads. This is number to look for when you get blank ads. How many of my clients gets an ad impression? I had 60%</p>
<p><strong>What is the Click Through Rate (CTR)?</strong><br />
Out of 60% of my clients who had ad impressions, 6.18% of them clicked the ad. The more they get clicked, the higher your revenue.</p>
<h2><a href="http://www.admob.com">Admob</a></h2>
<p>Offers both publishing and analytics. Currently offers both iPhone and Android. Able to publish ads for native app and mobile websites. This is my preferred ad network of choice as it is easier to setup than the others. And just recently, it was swallowed by Google, whether that is good or bad for us, we have yet to know.</p>
<p><a href="http://developer.admob.com/wiki/IPhone#SDK_Integration_instructions">AdMob Iphone SDK Integration</a></p>
<p>1. After signing up/registering to Admob you need to add your application in &#8220;Sites &#038; Apps&#8221; tab (2nd tab from the left).</p>
<p>2. Click on &#8220;Add Site/App&#8221; and you would be presented with what kind of site or app type (Mobile Web, Iphone App, Iphone Web and Android App). Select &#8220;Iphone App&#8221; and fill out the details..</p>
<p>3. If you go to &#8220;Sites &#038; Apps&#8221;, there&#8217;s a link &#8220;Setup&#8221; just under the Quick Links. You could download a sample AdMob application there wherein your publisherId is already built-in. Here&#8217;s a sample (<a href="/wordpress/wp-content/uploads/2009/12/admob_iphone_sdk_20091119.tar.gz" title="admob_iphone_sdk_20091119.tar.gz">admob_iphone_sdk_20091119.tar.gz</a>). Note that AdMob upgrade their code, notice the dates (20091119)? So it&#8217;s good practice to read the CHANGELOG.</p>
<p>4. Note your publisherId.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#pragma mark Admob delegate methods</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>publisherId <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;a14ac98028663b0&quot;</span>; <span style="color: #11740a; font-style: italic;">// bayanihan</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>5. Make the sample application from AdMob run first before integrating your app.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// To receive test ads rather than real ads...</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>useTestAd <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>; <span style="color: #11740a; font-style: italic;">//change this to NO later..</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>6. Normally, the problems/quirks I experience when integrating a 3rd Party Project are framework references. So, here&#8217;s mine:</p>
<p><img src="/wordpress/wp-content/uploads/2009/12/admob_frameworks.png" alt="admob_frameworks.png" border="0" width="221" height="172" /></p>
<p>Note: As of ver 20091119, I added <em>MessageUI.framework, AudioToolbox.framework, MediaPlayer.framework</em>. Prior to that build (200906xx), I don&#8217;t have those.  If you are compiling against iPhoneOS version 3, then you would need to reference <em>libAdMObDevice3_0.a</em> and <em>libAdMobSimulator3_0.a</em> (to run it in the simulator&#8211;but you would take this reference off when making an actual build)</p>
<p><img src="/wordpress/wp-content/uploads/2009/12/admob-iphoneos3.png" alt="admob-iphoneos3.png" border="0" width="204" height="85" /></p>
<p>7. Now, that both the testAd (YES) is working, it might take you a few hours before the real ad comes in. Be patient. :)</p>
<p>8. Integrate to your project. AdMob provided detailed examples on how to integrate depending on your needs&#8211;Interface Builder (IB), Programmatically or TableView.  Personally, I have used both IB and TableView and it works flawlessly.</p>
<p>9. I dont get an ad? I get an Ad? Which one? Check out the AdMobDelegate Methods.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>didReceiveAd<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>AdMobView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>adView <span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;AdMob: Did receive ad&quot;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>didFailToReceiveAd<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>AdMobView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>adView <span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;AdMob: Did fail to receive ad&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">//[self createMobclix];</span>
	<span style="color: #11740a; font-style: italic;">//[bannerCell setNeedsLayout];</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>10. Now once you have AdMob going, you want to be more efficient and get higher fill rates. You can checkout other Ad Platforms (<a href="https://developer.mobclix.com/">Mobclix</a>, <a href="www.adwhirl.com">Adwhirl</a>). Notice on step 9 above, that if I don&#8217;t get an ad from AdMob, I fire up an add from MobClix.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/12/iphone-dev-note-18-integrating-ads-admob-on-your-iphone-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Note #17: Displaying a custom view controller from a UITextField</title>
		<link>/wordpress/2009/11/iphone-note-17-displaying-a-custom-view-controller-from-a-uitextfield/</link>
		<comments>/wordpress/2009/11/iphone-note-17-displaying-a-custom-view-controller-from-a-uitextfield/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 00:49:56 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=636</guid>
		<description><![CDATA[Problem: I want my textFieldSearchAddress to display a seperate viewcontroller. Short Answer: Hide the keyboard by using [textField resignFirstResponder] then show the view controller. 1. Implement a UITextFieldDelegate. - &#40;BOOL&#41;textFieldShouldBeginEditing:&#40;UITextField *&#41;textField&#123; &#91;textField resignFirstResponder&#93;; &#91;self show&#93;; return NO; &#125; Be careful with the BOOL return of textFieldShouldBeginEditing. From the docs: &#8220;YES if an editing session should]]></description>
			<content:encoded><![CDATA[<p>Problem: I want my textFieldSearchAddress to display a seperate viewcontroller.</p>
<p><img src="/wordpress/wp-content/uploads/2009/11/textfield.png" alt="textfield.png" border="0" width="400" height="279" /></p>
<p>Short Answer: Hide the keyboard by using
<pre>[textField resignFirstResponder]</pre>
<p> then show the view controller.</p>
<p>1. Implement a UITextFieldDelegate.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>textFieldShouldBeginEditing<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITextField <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>textField<span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>textField resignFirstResponder<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>self show<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">return</span> <span style="color: #a61390;">NO</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Be careful with the BOOL return of textFieldShouldBeginEditing. From the docs: <em>&#8220;YES if an editing session should be initiated; otherwise, NO to disallow editing.&#8221;</em> </p>
<p>2. Show the view controller.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span>show<span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;show&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
	AddressViewController <span style="color: #002200;">*</span>addressViewController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>AddressViewController alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;AddressViewController&quot;</span> bundle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
	UINavigationController <span style="color: #002200;">*</span>nav <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UINavigationController alloc<span style="color: #002200;">&#93;</span> initWithRootViewController<span style="color: #002200;">:</span>addressViewController<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>self presentModalViewController<span style="color: #002200;">:</span>nav animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>addressViewController release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>nav release<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Download <a href="/wordpress/wp-content/uploads/2009/11/SimpleIB-textfield_custom_view_controller.zip" title="SimpleIB-textfield_custom_view_controller.zip">SimpleIB-textfield_custom_view_controller.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/11/iphone-note-17-displaying-a-custom-view-controller-from-a-uitextfield/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Subversion</title>
		<link>/wordpress/2009/11/subversion/</link>
		<comments>/wordpress/2009/11/subversion/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 22:22:01 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">/wordpress/?p=634</guid>
		<description><![CDATA[This post will contain a summary of information regarding subversion scattered from old posts. Installation on Debian 1. Packages #apt-get install subversion #apt-get install libapache2-svn 2. Login as root then create the repository. #cd /data #svnadmin create /repos --fs-type fsfs 3. Set the permissions #groupadd subversion #addgroup rupert subversion #addgroup www-data subversion &#160; #chown -Rf]]></description>
			<content:encoded><![CDATA[<p>This post will contain a summary of information regarding subversion scattered from old posts.</p>
<h3>Installation on Debian</h3>
<p>1. Packages</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">#apt-get install subversion
#apt-get install libapache2-svn</pre></div></div>

<p>2. Login as root then create the repository.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">#cd /data
#svnadmin create /repos --fs-type fsfs</pre></div></div>

<p>3. Set the permissions</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">#groupadd subversion
#addgroup rupert subversion
#addgroup www-data subversion
&nbsp;
#chown -Rf www-data:subversion /data/repos
#chmod -Rf 770 repos</pre></div></div>

<p>It&#8217;s better to set the necessary users and groups that would use subversion now. Later on, if we need to checkout using svn+ssh and setup a passwordless svn, then we won&#8217;t get permission issues.</p>
<p>4. In /etc/apache2/sites-available/2rmobile, add this to the configuration.</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">        &lt;Location /repos&gt;
        DAV svn
        SVNPath /data/repos
        SVNAutoversioning on
        AuthType Basic
        AuthName &quot;SVN - Your Project&quot;
        AuthUserFile /data/svn-auth-file
        Require valid-user
        &lt;/Location&gt;</pre></div></div>

<p>5. Enable the webdav module then restart apache.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">#a2enmod dav
#a2enmod dav_svn
#/etc/init.d/apache2 restart</pre></div></div>

<h3>Passwordless SVN</h3>
<p>On your local macbook pro (mbp), we need to generate the ssh keys from the local machine, upload it to the remote machine and append it in the authorized_keys.</p>
<p><em>On the local machine:</em></p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">#ssh-keygen -t rsa
...
#cd /Users/rupert/.ssh
#scp -r id_rsa.pub rupert@2rmobile.com:/home/rupert/.ssh/id_rsa_mbp.pub</pre></div></div>

<p><em>On the remote machine:</em></p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">#cd ~/.ssh
#touch authorized_keys
#cat id_rsa_mbp.pub &gt;&gt; authorized_keys</pre></div></div>

<p>Test on the local machine by doing</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">ssh rupert@2rmobile.com</pre></div></div>

<p>. In my mbp, a dialog box from keychain is asking for the password. To circumvent this, we can add the passphrase to our identities.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">#ssh-add -K
... enter the passphrase twice...
#ssh-add -k (adds it to the identities)
#ssh-add -l (lists the identities)</pre></div></div>

<p>Now the benefits of having a passwordless svn:<br />
- ofcourse it saves us a lot of time<br />
- rails capistrano deployment</p>
<p>References:<br />
<a href="http://www.howtoforge.com/debian_subversion_websvn">http://www.howtoforge.com/debian_subversion_websvn</a></p>
<h3>Subversion Tips and Tricks</h3>
<p><a href="http://subversion.tigris.org/faq.html#ssh-authorized-keys-trick">http://subversion.tigris.org/faq.html#ssh-authorized-keys-trick</a></p>
<p><strong>1. Checking out using svn+ssh and having passwordless ssh authentication. My personal favorite when working with personal projects since I have full control. </strong></p>
<pre>
svn co svn+ssh://www.2rmobile.com/data/repos/web/rails/halalan2010 halalan2010
</pre>
<p>But for work projects, I normally use webdav</p>
<pre>
svn co "http://www.2rmobile.com/repos/web/halalan2010" halalan2010
</pre>
<p><strong>2. svn+ssh on a custom or different port other than 22. I have my ssh on 2210, so we need to tell svn+ssh to use 2210</strong></p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">vim ~/.subversion/config
 41 [tunnels]
 42 ### Configure svn protocol tunnel schemes here.  By default, only
....
 53 ### built-in ssh scheme were not predefined, it could be defined
 54 ### as:
 55 ssh = $SVN_SSH ssh -p 2210</pre></div></div>

<p><a href="http://www.techper.net/2009/01/11/changing-port-number-of-svnssh-subversion-protocol/">http://www.techper.net/2009/01/11/changing-port-number-of-svnssh-subversion-protocol/</a></p>
<p><strong>3. svn diff</strong> &#8211; shows you the changes in a directory. This is useful for creating patches.</p>
<pre>
svn diff -r HEAD
svn st -q
</pre>
<p><strong>3. svn switch oldURL to newURL </strong>- very useful when I&#8217;m working at home or in the office, since the svn server has a public/private IP.</p>
<p><strong>4. svn log</strong> &#8211; shows you who committed and why (from the messages)</p>
<p><strong>5. ignoring specific files in a directory. i.e rails directories</strong></p>
<pre>svn propset svn:ignore "*.log" log</pre>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/11/subversion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Note #16: Creating a MKMapView using IB</title>
		<link>/wordpress/2009/10/iphone-dev-16-creating-a-mkmapview-using-ib/</link>
		<comments>/wordpress/2009/10/iphone-dev-16-creating-a-mkmapview-using-ib/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 06:25:59 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=590</guid>
		<description><![CDATA[In this tutorial we will be addking MKMapView using IB to a ViewController. 1. XCode -> File -> New Project -> View-based Application. Name the project &#8220;SimpleMapIB&#8221; 2. Make sure everything works out accordingly before doing anything. Let&#8217;s test from the iPhone Simulator. Click on &#8220;Build and Go&#8221;. You should see the iPhone Simulator running]]></description>
			<content:encoded><![CDATA[<p>In this tutorial we will be addking MKMapView using IB to a ViewController.</p>
<p>1. XCode -> File -> New Project -> View-based Application.</p>
<p>Name the project &#8220;SimpleMapIB&#8221;</p>
<p>2. Make sure everything works out accordingly before doing anything. Let&#8217;s test from the iPhone Simulator. Click on <b>&#8220;Build and Go&#8221;</b>. You should see the iPhone Simulator running with a gray background. Bring up the Debugger Console (XCode -> Run -> Console) as well and it should be free from errors.</p>
<p>3. Now double-click on &#8220;SimpleMapIBViewController.xib&#8221;, it should open in Interface Builder.</p>
<p>4. Drag a UIToolbar to the bottom. We will use the button as a GPS in our next tutorial.</p>
<p>5. Drag MKMapView to the middle of the screen.</p>
<p>6. IB -> save</p>
<p>7. Now we need to reference Mapkit. Go to XCode -> Project -> Edit Active Target &#8220;SimpleMapIB&#8221;. Click the + icon on the bottom left, choose MapKit.framework, then &#8220;Add&#8221;. </p>
<p><img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-1.png" alt="SimpleMapIB-1.png" border="0" width="400" height="421" /></p>
<p>You should see Mapkit added to the frameworks. </p>
<p><img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-2.png" alt="SimpleMapIB-2.png" border="0" width="207" height="105" /></p>
<p>You could also organize XCode&#8217;s left panel by dragging &#8220;MapKit.framework&#8221; to the Frameworks Group.</p>
<p><img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-3.png" alt="SimpleMapIB-3.png" border="0" width="227" height="132" /></p>
<p>7. Let&#8217;s code SimpleMapIBViewController.h</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span>
<span style="color: #6e371a;">#import &lt;MapKit/MapKit.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> SimpleMapIBViewController <span style="color: #002200;">:</span> UIViewController <span style="color: #002200;">&#123;</span>
	IBOutlet MKMapView <span style="color: #002200;">*</span>mapview;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet MKMapView <span style="color: #002200;">*</span>mapview;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>8. Now back to IB. Click on the &#8220;File&#8217;s Owner&#8221; and you should see your outlets displayed &#8220;Connections Inspector&#8221;. Drag &#8220;mapview&#8221; to MKMapView Control.</p>
<p><a href="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-4.png"><br />
<img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-4-sm.png" alt="SimpleMapIB-4-sm.png" border="0" width="300" height="333" /></a><br />
<em>Note: You can click for a bigger image.</em></p>
<p>9. Now to set &#8220;SimpleMapIBViewController&#8221; as the delegate. Click on the MKMapView, it should be highlighted and in the &#8220;Connections Inspector&#8221; notice the &#8220;delegate&#8221; come out in the Outlets. Drag it to the &#8220;Files Owner&#8221; to set &#8220;SimpleMapIBViewController&#8221; as the delegate.</p>
<p><a href="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-5.png" alt="SimpleMapIB-5.png"><img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-5-sm.png" alt="SimpleMapIB-5-sm.png" border="0" width="300" height="336" /></a><br />
<em>Note: You can click for a bigger image.</em></p>
<p>10. Now, let&#8217;s test. Hit &#8220;Clean All&#8221; then &#8220;Build and Go&#8221;. You should see something like this..</p>
<p><img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-6.png" alt="SimpleMapIB-6.png" border="0" width="150" height="225" /></p>
<p>11. Now to test that the delegate is setup accordingly, we can code on the viewDidLoad.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>viewDidLoad <span style="color: #002200;">&#123;</span>
    mapview.mapType <span style="color: #002200;">=</span> MKMapTypeSatellite;
&nbsp;
	<span style="color: #002200;">&#91;</span>super viewDidLoad<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>12, Now press command-Y for &#8220;Build and Debug&#8221;. We should see a satellite map instead.<br />
<img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-7.png" alt="SimpleMapIB-7.png" border="0" width="150" height="226" /></p>
<p>13. That seems a little bit dull, lets add a segmented control so we can switch between maptypes (standard, satellite, hybrid). In IB, drag a UISegmentedControl in the UIToolbar at the bottom. Add another segment, making a total of three. Then change the titles to &#8220;Normal&#8221;, &#8220;Sat&#8221;, &#8220;Hybrid&#8221; respectively.</p>
<p><img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-8.png" alt="SimpleMapIB-8.png" border="0" width="250" height="389" />.</p>
<p>14. Let&#8217;s code. In the interface, we need to add a method that would be called by the segmentedControl whened the values changed.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span>
<span style="color: #6e371a;">#import &lt;MapKit/MapKit.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> SimpleMapIBViewController <span style="color: #002200;">:</span> UIViewController <span style="color: #002200;">&#123;</span>
	IBOutlet MKMapView <span style="color: #002200;">*</span>mapview;
	IBOutlet UISegmentedControl <span style="color: #002200;">*</span>segmentedControlMapType;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet MKMapView <span style="color: #002200;">*</span>mapview;
<span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UISegmentedControl <span style="color: #002200;">*</span>segmentedControlMapType;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span>changeMapType<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Now in IB, click on the &#8220;File&#8217;s Owner&#8221; and you should see your outlets displayed &#8220;Connections Inspector&#8221;. Drag &#8220;segmentedControlMapType&#8221; to the segmented control just like what we did for mapview.</p>
<p>15. In the implementation, we can switch between the segmentIndex and display the corresponding MKMapType.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span>changeMapType<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>segmentedControlMapType.selectedSegmentIndex <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
		mapview.mapType <span style="color: #002200;">=</span> MKMapTypeStandard;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>segmentedControlMapType.selectedSegmentIndex <span style="color: #002200;">==</span> <span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
		mapview.mapType <span style="color: #002200;">=</span> MKMapTypeSatellite;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>segmentedControlMapType.selectedSegmentIndex <span style="color: #002200;">==</span> <span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
		mapview.mapType <span style="color: #002200;">=</span> MKMapTypeHybrid;
	<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>16. Now to hook the IBAction of the UISegmentedControl to the method. In IB, click on the segmented control and in the &#8220;Connections Inspector&#8221;, drag the &#8220;Value Changed&#8221; Event to the &#8220;File&#8217;s Owner&#8221; and choose &#8220;changeMapType&#8221;.</p>
<p><a href="<img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-9.png" alt="SimpleMapIB-9.png" border="0" width="600" height="675" />&#8220;><img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-9-sm.png" alt="SimpleMapIB-9-sm.png" border="0" width="300" height="338" /></a></p>
<p>17. Now test in the simulator again and the hybrid button should work.<br />
<img src="/wordpress/wp-content/uploads/2009/10/SimpleMapIB-10.png" alt="SimpleMapIB-10.png" border="0" width="323" height="480" /></p>
<p><a href="/wordpress/wp-content/uploads/2009/10/SimpleMapIB.zip" title="SimpleMapIB.zip">Download SimpleMapIB.zip</a></p>
<p>In my next tutorial, I would be hooking up a GPS button which handles location updates using CoreLocation.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/10/iphone-dev-16-creating-a-mkmapview-using-ib/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>iPhone Note #15: Omnigraffle iPhone Stencils, Screen Mockups via PPT, creating an iPhone interface before actual development</title>
		<link>/wordpress/2009/10/iphone-dev-note-15-omnigraffle-iphone-stencils-screen-mockups-via-ppt-creating-an-iphone-interface-before-actual-development/</link>
		<comments>/wordpress/2009/10/iphone-dev-note-15-omnigraffle-iphone-stencils-screen-mockups-via-ppt-creating-an-iphone-interface-before-actual-development/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 22:41:47 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=559</guid>
		<description><![CDATA[I can not argue enough how valuable an iphone stencil will be in seeing the overall design/flow of an application. I should have done this a long time ago. Well, I am also one of those eager developers who dives right into coding and see how it goes. But after having the fundamentals of iphone]]></description>
			<content:encoded><![CDATA[<p><img src="/wordpress/wp-content/uploads/2009/10/stencil.gif" alt="stencil.gif" border="0" width="350" height="346" /></p>
<p><em><strong>I can not argue enough how valuable an iphone stencil will be in seeing the overall design/flow of an application. I should have done this a long time ago.</strong></em>  </p>
<p>Well, I am also one of those eager developers who dives right into coding and see how it goes. But after having the fundamentals of iphone development, objective-c, and app-store submission, I&#8217;m taking on a different approach by creating screen mockups mainly for the following reasons:</p>
<p>1. Reach out quickly to the client. </p>
<p>2. Provides a bird&#8217;s eye view of the whole application. Provides alternative screens for a better user experience..</p>
<p>3. A follow up on the screen mockups is a powerpoint with actual links to other slides thus mimicing an iphone interface. Note, it is not a complete replica of the simulator but just enough for decision makers to understand what&#8217;s in there.</p>
<p><img src="/wordpress/wp-content/uploads/2009/10/stencil-ppt.jpg" alt="stencil-ppt.jpg" border="0" width="400" height="591" /></p>
<p><em>In powerpoint, you can just quickly overlay a transparent polygon on top of the UIButton then attach a hyperlink to another slide.</em></p>
<p>Hope this post helps you even if it&#8217;s not related to coding. On my next post, which is currently buried in my drafts&#8211;hopefully it will not be that long, I learned about integrating with Mobile Advertising Networks.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/10/iphone-dev-note-15-omnigraffle-iphone-stencils-screen-mockups-via-ppt-creating-an-iphone-interface-before-actual-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UPDATED: Bayanihan iPhone Project for Ondoy. Submitted.</title>
		<link>/wordpress/2009/10/bayanihan-iphone-project-for-ondoy-i-need-pictures/</link>
		<comments>/wordpress/2009/10/bayanihan-iphone-project-for-ondoy-i-need-pictures/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 05:53:45 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=544</guid>
		<description><![CDATA[I am a programmer currently in Melbourne, Australia hoping to raise awareness for the victims affected by typhoon Ondoy (Ketsana-international name). Experiencing a flood is not new to me as I was born and raised in Tumana, Marikina, Metro Manila. I was in primary school, when I could vividly remember my mother cooking and serving]]></description>
			<content:encoded><![CDATA[<p>I am a programmer currently in Melbourne, Australia hoping to raise awareness for the victims affected by typhoon Ondoy (Ketsana-international name). Experiencing a flood is not new to me as I was born and raised in Tumana, Marikina, Metro Manila. I was in primary school, when I could vividly remember my mother cooking and serving porridge to typhoon victims as our backyard was called &#8220;high ground&#8221; since it is near the main road (JP Rizal).</p>
<p>I was in college when Tumana bridge was built and helped me travel from my house to the University. Unfortunately, the river would swell and the flood would swallow the whole bridge after 2-3 days of rain. I called my mother on Sept 27 and was informed the typhoon poured over a whole month of rain in just a few hours! Don&#8217;t worry my mother is fine, however, there are those who are unfortunate enough who desperately call for our help. In my small way by making this application, I would like to show my support for them.</p>
<p>I&#8217;m almost finished with the Bayanihan iPhone project which I worked on over the weekend. It is a very simple app with scrollable images. The server side is almost finished and would display how many supported/downloaded the application in real time. I am hoping to upload the server side to my Linode hosting in the US asap. </p>
<p><b>How can you help?</b> I need pictures! Pictures from Tumana would be greatly appreciated, however, if you have other pictures, please do send them as well. I will be bundling 10 pictures inside the application. Please include your name, with subject: BAYANIHAN pix and send the pictures to my email address: rndguzmanjr@gmail.com</p>
<p>Hopefully I can submit the app to Apple within this week or early next week. Afterwards, we wait for the approval process within 2 weeks. Note, the app would be FREE. </p>
<p><b>UPDATE OCT-05-2009 9:00PM</b><br />
I took some pictures from facebook and dropped it in the project. It would look something like this when it is finished.</p>
<p><a href="/wordpress/wp-content/uploads/2009/10/bayanihan-sample-1.jpg"><img src="/wordpress/wp-content/uploads/2009/10/bayanihan-sample-1-small.jpg" alt="bayanihan-sample-1-small.jpg" border="0" width="800" height="301" /></a></p>
<p><strong>UPDATE OCT-11-2009</strong><br />
- Included proper credits for each photograph.<br />
- Added Admob.<br />
- Created logo, large application icon.</p>
<p><img src="/wordpress/wp-content/uploads/2009/10/Icon.png" alt="Icon.png" border="0" width="57" height="57" /></p>
<p><strong>UPDATE OCT-12-2009</strong><br />
Preparing for appstore submission..</p>
<p><strong>UPDATE OCT-13-2009</strong><br />
Submitted in AppStore. Currently, In-Review.</p>
<p><img src="/wordpress/wp-content/uploads/2009/10/0.jpg" alt="0.jpg" border="0" width="320" height="460" /></p>
<p><img src="/wordpress/wp-content/uploads/2009/10/8.jpg" alt="8.jpg" border="0" width="320" height="460" /></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/10/bayanihan-iphone-project-for-ondoy-i-need-pictures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Note #13: Drawing Point, Line, Polygon on top of MKMapview</title>
		<link>/wordpress/2009/09/iphone-devnote-13-drawing-point-line-polygon-on-top-of-mkmapview/</link>
		<comments>/wordpress/2009/09/iphone-devnote-13-drawing-point-line-polygon-on-top-of-mkmapview/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 00:10:36 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=529</guid>
		<description><![CDATA[Now I have a reason to study Quartz2D! I am trying to draw a point, line and polygon on top of MKMapview. I will list below important links for reference: 1. Always use Apple&#8217;s iPhone OS Reference Library Documentation.. Under &#8220;Topics&#8221; > &#8220;Graphics &#038; Animation&#8221; you will find a lot of references, guides and sample]]></description>
			<content:encoded><![CDATA[<p>Now I have a reason to study Quartz2D! I am trying to draw a point, line and polygon on top of MKMapview. I will list below important links for reference:</p>
<p>1. Always use Apple&#8217;s <a href="http://developer.apple.com/iphone/library/navigation/index.html">iPhone OS Reference Library Documentation.</a>. Under &#8220;Topics&#8221; > &#8220;Graphics &#038; Animation&#8221; you will find a lot of references, guides and sample code.</p>
<p>2. Start out with the <a href="">Getting Started with Graphics and Animation. </a> Note, if you ever read the line below and try to find Finger Sketch, please drop me a comment. I could not find it anywhere!</p>
<blockquote><p><cite>&#8220;Next, examine the Finger Sketch sample code in Xcode.&#8221;</cite></p></blockquote>
<p>3. <a href="http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/GraphicsandDrawing/GraphicsandDrawing.html#//apple_ref/doc/uid/TP40007072-CH10-SW1">iPhone Application Programming Guide: Graphics and Drawing</a>.</p>
<p>4. Note: I haven&#8217;t read everything on <a href="http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/Introduction/Introduction.html">Quartz 2D Programming Guide</a>, but I went straight to the <em>Paths</em> Section.</p>
<p>5. Lets look at some sample codes, especially the QuartzDemo.</p>
<p>6. Now, I presume you know IB, add a MKMapView and a UIToolbar at the bottom. Add four UIBarButtonItems for: Map, Point, Line, Polygon. Set MKMapView&#8217;s delegate to the File&#8217;s Owner. Hook up the UIBarButtonItem IBOutlets to your buttons, so we can change the appearance of the buttons when pressed. Lastly, hook up our IBAction methods for each button.</p>
<p>The Map button allows to pan/zoom on the Map. If any of the three geometry buttons (PT, LN, PG) is pressed, we unhide the GeometryView(which is a UIView) to allow touchEvents to proceed.</p>
<p>TO DO: Watch out for this segment as I will update it with code later.</p>
<p>7. Now to draw a line, we implement the code below in our GeometryView.drawRect method. As we loop through each Pin, we add a line to the point. Afterwards, we stroke the path, thus drawing the lines.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">CGContextRef context <span style="color: #002200;">=</span> UIGraphicsGetCurrentContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Drawing lines with a white stroke color</span>
CGContextSetRGBStrokeColor<span style="color: #002200;">&#40;</span>context, <span style="color: #2400d9;">1.0</span>, <span style="color: #2400d9;">1.0</span>, <span style="color: #2400d9;">1.0</span>, <span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Draw them with a 2.0 stroke width so they are a bit more visible.</span>
CGContextSetLineWidth<span style="color: #002200;">&#40;</span>context, <span style="color: #2400d9;">2.0</span><span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> <span style="color: #002200;">&#91;</span>pinFactory actualPinCount<span style="color: #002200;">&#93;</span> &gt; <span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
&nbsp;
	Pin <span style="color: #002200;">*</span>pin1 <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>Pin <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>pinFactory pinArray<span style="color: #002200;">&#93;</span> objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
	CGPoint pt1 <span style="color: #002200;">=</span> pin1.touchLocation;
	CGContextMoveToPoint<span style="color: #002200;">&#40;</span>context, pt1.x, pt1.y<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> i <span style="color: #002200;">=</span> <span style="color: #2400d9;">1</span>; i &lt; <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>pinFactory actualPinCount<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
		Pin <span style="color: #002200;">*</span>pin2 <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>Pin <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>pinFactory pinArray<span style="color: #002200;">&#93;</span> objectAtIndex<span style="color: #002200;">:</span>i<span style="color: #002200;">&#93;</span>;
		CGPoint pt2 <span style="color: #002200;">=</span> pin2.touchLocation;
		CGContextAddLineToPoint<span style="color: #002200;">&#40;</span>context, pt2.x, pt2.y<span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	CGContextStrokePath<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p><img src="/wordpress/wp-content/uploads/2009/09/line.png" alt="line.png" border="0" width="320" height="481" /></p>
<p>8. To draw a polygon, we close the path of lines then fill the polygon.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">CGContextClosePath<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;
&nbsp;
CGContextDrawPath<span style="color: #002200;">&#40;</span>context, kCGPathFillStroke<span style="color: #002200;">&#41;</span>;</pre></div></div>

<p><img src="/wordpress/wp-content/uploads/2009/09/poly.png" alt="poly.png" border="0" width="320" height="481" /></p>
<p>Note: I&#8217;ll try to post the sample code when I have time. I&#8217;m trying to minimize blogging to 10 mins per post as my work tasks/personal development tasks is piling up&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/09/iphone-devnote-13-drawing-point-line-polygon-on-top-of-mkmapview/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>iPhone Note #12: Adding a UIButton on a UITableViewCell (Borderless)</title>
		<link>/wordpress/2009/09/iphone-note-12-adding-a-uibutton-on-a-uitableviewcell-borderless/</link>
		<comments>/wordpress/2009/09/iphone-note-12-adding-a-uibutton-on-a-uitableviewcell-borderless/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 00:58:08 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=523</guid>
		<description><![CDATA[1. Im trying to add two UIbuttons to a UITableViewCell, similar to the contacts app. Creating the UIButtons programmatically and adding them to the cell&#8217;s subview is trivial. However the interface is a bit different from the contacts app, see image here&#8230; cell = &#91;&#91;&#91;UITableViewCell alloc&#93; initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@&#34;ButtonCell&#34;&#93; autorelease&#93;; &#160; UIButton *buttonLeft = &#91;UIButton buttonWithType:UIButtonTypeRoundedRect&#93;;]]></description>
			<content:encoded><![CDATA[<p>1. Im trying to add two UIbuttons to a UITableViewCell, similar to the contacts app. Creating the UIButtons programmatically and adding them to the cell&#8217;s subview is trivial. However the interface is a bit different from the contacts app, see image here&#8230;</p>
<p><img src="/wordpress/wp-content/uploads/2009/09/UIButtons-dirty.png" alt="UIButtons-dirty.png" border="0" width="320" height="68" /></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UITableViewCell alloc<span style="color: #002200;">&#93;</span> initWithStyle<span style="color: #002200;">:</span>UITableViewCellStyleDefault reuseIdentifier<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;ButtonCell&quot;</span><span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
&nbsp;
UIButton <span style="color: #002200;">*</span>buttonLeft <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIButton buttonWithType<span style="color: #002200;">:</span>UIButtonTypeRoundedRect<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonLeft setTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Left&quot;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonLeft setFrame<span style="color: #002200;">:</span> CGRectMake<span style="color: #002200;">&#40;</span> 10.0f, 3.0f, 145.0f, 40.0f<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonLeft addTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>addToFavorites<span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span>UIControlEventTouchUpInside<span style="color: #002200;">&#93;</span>;
&nbsp;
UIButton <span style="color: #002200;">*</span>buttonRight <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIButton buttonWithType<span style="color: #002200;">:</span>UIButtonTypeRoundedRect<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonRight setTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Right&quot;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonRight setFrame<span style="color: #002200;">:</span> CGRectMake<span style="color: #002200;">&#40;</span> 165.0f, 3.0f, 145.0f, 40.0f<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonRight addTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>addToFavorites<span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span>UIControlEventTouchUpInside<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#91;</span>cell addSubview<span style="color: #002200;">:</span>buttonLeft<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>cell addSubview<span style="color: #002200;">:</span>buttonRight<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>2. So to make the background the same as <em>UITableViewStyleGrouped</em>, we can implement:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">cell.backgroundColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor groupTableViewBackgroundColor<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>But I could still see the border of the UITableViewCell.. see image below&#8230;<br />
<img src="/wordpress/wp-content/uploads/2009/09/UIButtons-not-so-clean.png" alt="UIButtons-not-so-clean.png" border="0" width="318" height="61" /></p>
<p>3. The crux of it was to implement a UIView, set the background as <em>UITableViewStyleGrouped</em> and add that as a cell&#8217;s backgroundView.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UITableViewCell alloc<span style="color: #002200;">&#93;</span> initWithStyle<span style="color: #002200;">:</span>UITableViewCellStyleDefault reuseIdentifier<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;ButtonCell&quot;</span><span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
&nbsp;
UIView <span style="color: #002200;">*</span>backgroundView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIView alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span>0.0f, 0.0f, 320.0f, 44.0f<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
backgroundView.backgroundColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor groupTableViewBackgroundColor<span style="color: #002200;">&#93;</span>;
&nbsp;
cell.backgroundView <span style="color: #002200;">=</span> backgroundView;
&nbsp;
UIButton <span style="color: #002200;">*</span>buttonLeft <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIButton buttonWithType<span style="color: #002200;">:</span>UIButtonTypeRoundedRect<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonLeft setTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Left&quot;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonLeft setFrame<span style="color: #002200;">:</span> CGRectMake<span style="color: #002200;">&#40;</span> 10.0f, 3.0f, 145.0f, 40.0f<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonLeft addTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>addToFavorites<span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span>UIControlEventTouchUpInside<span style="color: #002200;">&#93;</span>;
&nbsp;
UIButton <span style="color: #002200;">*</span>buttonRight <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIButton buttonWithType<span style="color: #002200;">:</span>UIButtonTypeRoundedRect<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonRight setTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Right&quot;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonRight setFrame<span style="color: #002200;">:</span> CGRectMake<span style="color: #002200;">&#40;</span> 165.0f, 3.0f, 145.0f, 40.0f<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>buttonRight addTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>addToFavorites<span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span>UIControlEventTouchUpInside<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#91;</span>cell addSubview<span style="color: #002200;">:</span>buttonLeft<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>cell addSubview<span style="color: #002200;">:</span>buttonRight<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#91;</span>backgroundView release<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Now the interface is a whole lot cleaner and the resulting image is better&#8230;</p>
<p><img src="/wordpress/wp-content/uploads/2009/09/UIButtons-clean.png" alt="UIButtons-clean.png" border="0" width="320" height="62" /></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/09/iphone-note-12-adding-a-uibutton-on-a-uitableviewcell-borderless/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>iPhone Note #11: Unit Testing</title>
		<link>/wordpress/2009/09/iphone-note-11-unit-testing/</link>
		<comments>/wordpress/2009/09/iphone-note-11-unit-testing/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 05:31:43 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>
		<category><![CDATA[mac]]></category>

		<guid isPermaLink="false">/wordpress/?p=518</guid>
		<description><![CDATA[Test first, develop later! That&#8217;s the greeting when you visit OCUnit, similar to JUnit. Note that for this tutorial, you do not need to install OCUnit as it comes &#8220;built-in&#8221; in XCode as of v2.1. 1. Create a new iPhone Window-based application project &#8220;SampleTest&#8221;. 2. Our subject for testing is Converter.m which converts kilometers to]]></description>
			<content:encoded><![CDATA[<p>Test first, develop later! That&#8217;s the greeting when you visit <a href="http://www.sente.ch/software/ocunit/">OCUnit</a>, similar to JUnit. Note that for this tutorial, you do not need to install OCUnit as it comes &#8220;built-in&#8221; in XCode as of v2.1.</p>
<p>1. Create a new iPhone Window-based application project &#8220;SampleTest&#8221;.</p>
<p>2. Our subject for testing is Converter.m which converts kilometers to meters. Let&#8217;s implement an incorrect conversion by specifying 1km = 100 meters (should be 1000 meters) so we can see that the unit test captures it below&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;Converter.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> Converter
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>init<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
&nbsp;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>convertKilometersToMeters<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>km<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> km <span style="color: #002200;">*</span> <span style="color: #2400d9;">100</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>3. Add another target &#8220;UnitTests&#8221;. Right click on Targets -> Add -> New Target&#8230; -> Choose Unit Test Bundle. </p>
<p><img src="/wordpress/wp-content/uploads/2009/09/unit-test-bundle.png" alt="unit-test-bundle.png" border="0" width="400" height="143" /></p>
<p>4. Name it &#8220;UnitTests&#8221;. After hitting submit, you will be presented with the project settings for &#8220;UnitTests&#8221;.</p>
<p><img src="/wordpress/wp-content/uploads/2009/09/unit-test-name2.png" alt="unit-test-name2.png" border="0" width="200" height="90" /></p>
<p>5. Go to the General Tab -> Click on the &#8220;+&#8221; icon above &#8220;Linked Libraries&#8221;. Choose &#8220;SampleTest&#8221; as the application we have direct dependency with.</p>
<p><img src="/wordpress/wp-content/uploads/2009/09/unit-test-dependency-3.png" alt="unit-test-dependency-3.png" border="0" width="300" height="452" /></p>
<p>6. Close the Settings. To check, navigate under &#8220;Groups &#038; Files&#8221; -> Targets. You should see the SampleTest Application Icon just below &#8220;UnitTests&#8221;.</p>
<p><img src="/wordpress/wp-content/uploads/2009/09/unit-test-tree-4.png" alt="unit-test-tree-4.png" border="0" width="225" height="191" /></p>
<p>7. Right Click on &#8220;Sample Test&#8221; -> Add -> New File&#8230;</p>
<p><img src="/wordpress/wp-content/uploads/2009/09/unit-test-class5.png" alt="unit-test-class5.png" border="0" width="400" height="300" /></p>
<p>8. Name the file &#8220;ConverterTest. Don&#8217;t forget to also create the header file (default). Specify it also in a different directory under &#8220;Location&#8221;. Then check the UnitTests as the &#8220;Targets&#8221;. When you hit &#8220;Finish&#8221; it will ask you to create the folder &#8220;Tests&#8221;</p>
<p><img src="/wordpress/wp-content/uploads/2009/09/unit-test-class6.png" alt="unit-test-class6.png" border="0" width="400" height="294" /></p>
<p>Tip: Keep things organize and put it under a &#8220;Tests&#8221; Group. Right Click on &#8220;Sample Test&#8221; -> Add -> New Group&#8230; Name it &#8220;Tests&#8221;, then drag the files (ConverterTest.h and ConverterTest.m) into that group.</p>
<p>9. Open up ConverterTest.h and notice that &#8220;SenTestingKit.h&#8221; is already imported. Now let&#8217;s add method testKilometersToMeters as shown below. Test methods usually start out with a <em>test</em> prefix.</p>
<p>In the implementation, let&#8217;s import Converter.h and use STAssertTrue. To test the convertKilometersToMeters method, we are asserting that the result should be 1000. If not, then we should know! That is why we are writing a unit test for.. making sure that our implementation doesn&#8217;t break.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;ConverterTest.h&quot;</span>
<span style="color: #6e371a;">#import &quot;Converter.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> ConverterTest
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>testKilometersToMeters<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">int</span> km <span style="color: #002200;">=</span> <span style="color: #2400d9;">1</span>;
	Converter <span style="color: #002200;">*</span>converter <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Converter alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">int</span> meters <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>converter convertKilometersToMeters<span style="color: #002200;">:</span>km<span style="color: #002200;">&#93;</span>;
	STAssertTrue<span style="color: #002200;">&#40;</span>meters <span style="color: #002200;">==</span> <span style="color: #2400d9;">1000</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;converting %d km to meters should equal 1000, instead received %d&quot;</span>, km, meters<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>12. Now, before we build our target &#8220;UnitTests&#8221;, we need to include additional class references from our application. Drag Converter.m to the &#8220;Compile Sources&#8221; under UnitTests.</p>
<p><img src="/wordpress/wp-content/uploads/2009/09/unit-test-drag7.png" alt="unit-test-drag7.png" border="0" width="147" height="400" /></p>
<p>13. Now we can build. There are many ways to do this. My preference is to do a clean build when testing. Right Click on Sample Test then choose &#8220;Clean SampleTest&#8221;. Afterwards choose &#8220;Build SampleTest&#8221;.  </p>
<p><img src="/wordpress/wp-content/uploads/2009/09/unit-test-build8.png" alt="unit-test-build8.png" border="0" width="200" height="154" /></p>
<p>If you have a succesful build for SampleTest, lets do the same for our &#8220;UnitTests&#8221;.</p>
<p><img src="/wordpress/wp-content/uploads/2009/09/unit-test-build9.png" alt="unit-test-build9.png" border="0" width="230" height="236" /></p>
<p>13. Here&#8217;s the crux of it. Notice the <em>error</em> in your &#8220;Build Results&#8221;?</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">/Users/rupert/projects/iphone/SampleTest/Tests/ConverterTest.m:18: error: -[ConverterTest testKilometersToMeters] : &quot;meters == 1000&quot; should be true. converting 1 km to meters should equal 1000, instead received 100</pre></div></div>

<p><img src="/wordpress/wp-content/uploads/2009/09/unit-test-results.png" alt="unit-test-results.png" border="0" width="400" height="422" /></p>
<p>Now changing the correct implementation of convertKilometersToMeters will put the error away and you will have a successful build.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>convertKilometersToMeters<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>km<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> km <span style="color: #002200;">*</span> <span style="color: #2400d9;">1000</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>14. Look up the assert methods from SenTest.h.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;Foundation/NSObject.h&gt;</span>
<span style="color: #6e371a;">#import &quot;SenTest.h&quot;</span>
&nbsp;
<span style="color: #6e371a;">#define STAssertNil(a1, description, ...)</span>
<span style="color: #6e371a;">#define STAssertNotNil(a1, description, ...)</span>
<span style="color: #6e371a;">#define STAssertTrue(expression, description, ...)</span>
<span style="color: #6e371a;">#define STAssertFalse(expression, description, ...)</span>
<span style="color: #6e371a;">#define STAssertEqualObjects(a1, a2, description, ...)</span>
<span style="color: #6e371a;">#define STAssertEquals(a1, a2, description, ...)</span>
<span style="color: #6e371a;">#define STAssertEqualsWithAccuracy(left, right, accuracy, description, ...)</span>
<span style="color: #6e371a;">#define STAssertFalseNoThrow(expression, description, ...)</span>
....</pre></div></div>

<p>References:</p>
<p><a href="http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/UnitTesting/Articles/CreatingTests.html">http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/UnitTesting/Articles/CreatingTests.html</a></p>
<p><a href="http://developer.apple.com/tools/unittest.html">http://developer.apple.com/tools/unittest.html</a></p>
<p>Download: <a href="/wordpress/wp-content/uploads/2009/09/SampleTest.zip" title="SampleTest.zip">SampleTest.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/09/iphone-note-11-unit-testing/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>iPhone Note #10: Creating Custom Settings</title>
		<link>/wordpress/2009/09/iphone-note-10-creating-custom-settings/</link>
		<comments>/wordpress/2009/09/iphone-note-10-creating-custom-settings/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 04:47:49 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=499</guid>
		<description><![CDATA[1. Create a directory on your desktop, name it &#8220;Foo&#8221; 2. Download this Sample_plist.txt and place it inside foo. Name it as Root.plist Foo/ Foo/Root.plist 3. Rename Foo to Settings.bundle Settings.bundle/ Settings.bundle/Root.plist 4. Drag it to your project. 5. To retrieve a value from the settings.. For example, if we want to retrieve if the]]></description>
			<content:encoded><![CDATA[<p><img src="/wordpress/wp-content/uploads/2009/09/settings-overview.gif" alt="settings-overview.gif" border="0" width="400" height="176" /></p>
<p>1. Create a directory on your desktop, name it &#8220;Foo&#8221;</p>
<p>2. Download this <a href="/wordpress/wp-content/uploads/2009/09/Sample_plist.txt" title="Sample_plist.txt">Sample_plist.txt</a> and place it inside foo. Name it as Root.plist</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Foo<span style="color: #000000; font-weight: bold;">/</span>
Foo<span style="color: #000000; font-weight: bold;">/</span>Root.plist</pre></div></div>

<p>3. Rename Foo to Settings.bundle</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Settings.bundle<span style="color: #000000; font-weight: bold;">/</span>
Settings.bundle<span style="color: #000000; font-weight: bold;">/</span>Root.plist</pre></div></div>

<p>4. Drag it to your project.</p>
<p><img src="/wordpress/wp-content/uploads/2009/09/settings-bundle.gif" alt="settings-bundle.gif" border="0" width="234" height="187" /></p>
<p>5. To retrieve a value from the settings.. For example, if we want to retrieve if the <em>&#8220;enabled&#8221;</em> switch is on or off?</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSUserDefaults</span> <span style="color: #002200;">*</span>defaults <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSUserDefaults</span> standardUserDefaults<span style="color: #002200;">&#93;</span>;
<span style="color: #a61390;">BOOL</span> b <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>defaults boolForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;enabled_preference&quot;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/09/iphone-note-10-creating-custom-settings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mac Softwares and CheatSheet</title>
		<link>/wordpress/2009/08/mac-softwares-and-cheatsheet/</link>
		<comments>/wordpress/2009/08/mac-softwares-and-cheatsheet/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 11:36:15 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[mac]]></category>

		<guid isPermaLink="false">/wordpress/?p=490</guid>
		<description><![CDATA[1. iTerm &#8211; terminal with tabs. 2. MarsEdit- Blog Software. Im doing a local post on a local wordpress then copying and pasting to a remote wordpress. 3. Mac Shortcuts from http://www.danrodney.com/mac/index.html. Here&#8217;s a local post and another one. 4. How to create an ISO? hdiutil makehybrid -o CS3v1.iso CS3 5. chmOX &#8211; CHM Viewer]]></description>
			<content:encoded><![CDATA[<p>1. <a href="http://iterm.sourceforge.net/download.shtml">iTerm</a> &#8211; terminal with tabs. </p>
<p>2. <a href="http://www.red-sweater.com/marsedit/">MarsEdit</a>- Blog Software. Im doing a local post on a local wordpress then copying and pasting to a remote wordpress.</p>
<p>3. Mac Shortcuts from <a href="http://www.danrodney.com/mac/index.html">http://www.danrodney.com/mac/index.html</a>. Here&#8217;s a <a href="/wordpress/2008/08/mac-shortcuts/">local post</a> and another <a href="/wordpress/2008/11/mac-tip-of-the-day-know-your-shortcuts/">one.</a></p>
<p>4. How to create an ISO?</p>
<pre>hdiutil makehybrid -o CS3v1.iso CS3</pre>
<p>5. <a href="http://chmox.sourceforge.net">chmOX</a> &#8211; CHM Viewer in OSX.</p>
<p>6. <a href="http://code.google.com/p/git-osx-installer/">Git</a> for OS X from google code.</p>
<p>7. Open a finder from terminal</p>
<pre>open .</pre>
<p>8. Keychain Access asking on passwordless ssh?</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh-add</span>
Enter passphrase: <span style="color: #000000; font-weight: bold;">******</span>
<span style="color: #c20cb9; font-weight: bold;">ssh-add</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">&lt;</span>To list your identities<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/08/mac-softwares-and-cheatsheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
