<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>BlackBerry Developer Blog &#187; Libraries</title>
	<atom:link href="http://devblog.blackberry.com/tag/libraries/feed/" rel="self" type="application/rss+xml" />
	<link>http://devblog.blackberry.com</link>
	<description></description>
	<lastBuildDate>Thu, 23 May 2013 19:58:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='devblog.blackberry.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/9ef0a66c09615fa946c4179662398878?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>BlackBerry Developer Blog &#187; Libraries</title>
		<link>http://devblog.blackberry.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://devblog.blackberry.com/osd.xml" title="BlackBerry Developer Blog" />
	<atom:link rel='hub' href='http://devblog.blackberry.com/?pushpress=hub'/>
		<item>
		<title>Touch Anywhere (on the screen) You Want With Hammer.js and BlackBerry 10 WebWorks</title>
		<link>http://devblog.blackberry.com/2013/02/hammer-js/</link>
		<comments>http://devblog.blackberry.com/2013/02/hammer-js/#comments</comments>
		<pubDate>Fri, 08 Feb 2013 19:52:55 +0000</pubDate>
		<dc:creator>chadtatro</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[WebWorks]]></category>
		<category><![CDATA[gestures]]></category>
		<category><![CDATA[Hammer.js]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Libraries]]></category>
		<category><![CDATA[webworks]]></category>

		<guid isPermaLink="false">http://devblog.blackberry.com/?p=13334</guid>
		<description><![CDATA[With the launch of BlackBerry 10 and all touch devices ready to rock and roll, you may be interested in adding touch or multi-touch gestures in to your BlackBerry WebWorks apps. I came across an amazing JavaScript library called Hammer.js which makes it super easy to incorporate gestures into your application with only a few [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=13334&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>With the launch of <a href="http://global.blackberry.com/blackberry-10.html" target="_blank">BlackBerry 10</a> and all touch devices ready to rock and roll, you may be interested in adding touch or multi-touch gestures in to your <a href="developer.blackberry.com/html5" target="_blank">BlackBerry WebWorks</a> apps.</p>
<p>I came across an amazing JavaScript library called <a href="http://eightmedia.github.com/hammer.js/" target="_blank">Hammer.js</a> which makes it super easy to incorporate gestures into your application with only a few lines of code. The library is extremely lightweight, running ~2KB minified, and handles all of the legwork for you.</p>
<p>Hammer.js supports quite a few gestures too:</p>
<ul>
<li>Tap</li>
<li>Double Tap</li>
<li>Hold</li>
<li>Swipe</li>
<li>Drag</li>
<li>Transform (Pinching)</li>
</ul>
<p>Of course, what would touch events be without the actual Event data? When a user interacts with the screen, Hammer.js reports back to you with all of the information related to the touch. You can find out how long somebody touched the screen, where they touched, which direction they were swiping or dragging, the momentum of the swipe, and so on</p>
<p>So, why would you want use Hammer.js in your projects?</p>
<p><span id="more-13334"></span></p>
<h3><strong>It’s lightweight</strong></h3>
<p>Sure, there are other libraries out there that handle gestures, but it&#8217;s important to think about resources when creating mobile apps. Hammer.js runs about 2kb (minified) and leaves a very tiny footprint.</p>
<h3><strong>Simple to use</strong></h3>
<p>The syntax is incredibly easy to both use and understand. There&#8217;s even a jQuery plugin available if you&#8217;re like me and like to take shortcuts in your code.</p>
<h3><strong>Plays nice with others</strong></h3>
<p>Hammer.js works well alongside other libraries and frameworks. Whether you&#8217;re using jQuery, bbUI.js, Backbone.js, or others, you should have no worries that Hammer.js will interfere. It performs very well, and doesn&#8217;t get in the way.</p>
<h3><strong>Check out my sample app!</strong></h3>
<p>I worked very hard for what seemed like minutes, creating an awesome sample app to show how easy it is to use the Hammer.js library. Check it out in our <a href="https://github.com/blackberry/BB10-WebWorks-Samples/tree/master/gestures" target="_new">GitHub repo</a> &#8211; there’s even a special appearance by the one-and-only <a href="http://twitter.com/jesseariss" target="_new">Jesse Ariss</a>!</p>
<p><img class="aligncenter size-full wp-image-13336" alt="" src="http://rimdevblog.files.wordpress.com/2013/01/hammerjs.jpg" /></p>
<p>If you have any questions, or comments, feel free to hit me up on Twitter. I like the attention. <strong><a href="http://twitter.com/chadtatro" target="_new">@chadtatro</a></strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/13334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/13334/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=13334&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2013/02/hammer-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0fb86e7b2b71616806266b535686102c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ctetreault1980</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2013/01/hammerjs.jpg" medium="image" />
	</item>
		<item>
		<title>Lightweight Maps for Mobile, Part 1: Introduction to Map APIs and Libraries</title>
		<link>http://devblog.blackberry.com/2012/05/lightweight-maps-for-mobile-part-1/</link>
		<comments>http://devblog.blackberry.com/2012/05/lightweight-maps-for-mobile-part-1/#comments</comments>
		<pubDate>Tue, 08 May 2012 13:18:17 +0000</pubDate>
		<dc:creator>Jim Ing</dc:creator>
				<category><![CDATA[How-to]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[apis]]></category>
		<category><![CDATA[Bing]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[Libraries]]></category>
		<category><![CDATA[MapQuest]]></category>
		<category><![CDATA[maps]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[mobile web apps]]></category>
		<category><![CDATA[tile naming conventions]]></category>

		<guid isPermaLink="false">http://devblog.blackberry.com/?p=9328</guid>
		<description><![CDATA[Discussing the creation of lightweight maps for mobile web apps.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=9328&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>When it comes to building interactive maps for desktop web, most of us are quite comfortable using APIs like Google Maps or Bing Maps. But when we need to port or build something for mobile, it often feels like we&#8217;re crumpling a clean sheet of paper into a paper ball. Certainly, dealing with a smaller screen size, slower processor, and less memory can feel like a frustrating step backwards. But if you consider that mobile devices have touch screens, cameras, microphones, accelerometers, wireless and GPS capabilities on top of being portable, mobile devices are in a way better place than desktop PCs. So if we take the time to understand their limitations and features, we can build lightweight applications that are more like origami — compact, elegant, and functional — instead of like a crumpled paper ball that you&#8217;re ready to throw in the trash can.</p>
<table style="border:1px solid #DDD;border-radius:10px;">
<tbody>
<tr>
<td style="padding:10px;text-align:center;font-weight:bold;">Desktop web development is like this&#8230;</td>
<td style="padding:10px;text-align:center;font-weight:bold;">Mobile web can feel like this&#8230;</td>
<td style="padding:10px;text-align:center;font-weight:bold;">But mobile should and can be like this&#8230;</td>
</tr>
<tr>
<td style="padding:10px;text-align:center;"><a href="http://rimdevblog.files.wordpress.com/2012/05/sheet_sm.png"><img class="aligncenter size-full wp-image-9341" title="sheet_sm" src="http://rimdevblog.files.wordpress.com/2012/05/sheet_sm.png?w=140&#038;h=151" alt="" width="140" height="151" /></a></td>
<td style="padding:10px;text-align:center;"><a href="http://rimdevblog.files.wordpress.com/2012/05/crumpled_sm.png"><img class="aligncenter size-full wp-image-9342" title="crumpled_sm" src="http://rimdevblog.files.wordpress.com/2012/05/crumpled_sm.png?w=90&#038;h=90" alt="" width="90" height="90" /></a></td>
<td style="padding:10px;text-align:center;"><a href="http://rimdevblog.files.wordpress.com/2012/05/origami_sm.png"><img class="aligncenter size-full wp-image-9343" title="origami_sm" src="http://rimdevblog.files.wordpress.com/2012/05/origami_sm.png?w=140&#038;h=80" alt="" width="140" height="80" /></a></td>
</tr>
<tr>
<td style="padding:10px;text-align:center;">fairly standard</td>
<td style="padding:10px;text-align:center;">frustrating</td>
<td style="padding:10px;text-align:center;">compact, elegant, and functional</td>
</tr>
</tbody>
</table>
<p><span id="more-9328"></span></p>
<p>So where do we start? Well, when it comes to mobile web apps, file and transfer size matters — the smaller, the better. So the first thing I wanted to do was survey the landscape and compare the size of some of the different APIs that are available. (If I missed some that are lightweight, please let me know.) Although <a href="http://maps.google.com/" target="_blank">Google Maps</a> is the most popular API out there (and deservedly so), it&#8217;s JavaScript API and tile images are quite large. In my tests below, I created basic map pages for a 1024×768 screen using each of the APIs, and I found that Google Maps transfers about <span style="background-color:#b94a48;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">950 KB</span> of data! This can be a problem for smartphones since they have limited memory. Besides causing an application to crash, a memory-intensive app can also chew up precious kilobytes from a user&#8217;s data plan, and it can drain their battery faster than they want. Thankfully, we have some choices&#8230;</p>
<table style="border:1px solid #DDD;border-radius:10px;">
<tbody>
<tr style="background-color:#000;color:#fff;">
<td style="padding:10px;text-align:center;">API Provider</td>
<td style="padding:10px;text-align:center;">Requests</td>
<td style="padding:10px;text-align:center;">Transferred<br />
(KB)</td>
<td style="padding:10px;text-align:center;">Images<br />
(KB)</td>
<td style="padding:10px;text-align:center;">Scripts<br />
(KB)</td>
</tr>
<tr>
<td style="padding:10px;"><a href="http://msdn.microsoft.com/en-us/library/bb429619.aspx" target="_blank">Bing 6.3</a></td>
<td style="padding:10px;">43</td>
<td style="padding:10px;">596.07</td>
<td style="padding:10px;">358.06 (35)</td>
<td style="padding:10px;">228.92 (4)</td>
</tr>
<tr style="background-color:#eee;">
<td style="padding:10px;"><a href="http://msdn.microsoft.com/en-us/library/ff710049.aspx" target="_blank">Bing 6.3c (Core)</a></td>
<td style="padding:10px;">43</td>
<td style="padding:10px;">423.53</td>
<td style="padding:10px;">371.28 (34)</td>
<td style="padding:10px;">46.72 (5)</td>
</tr>
<tr>
<td style="padding:10px;"><a href="http://msdn.microsoft.com/en-us/library/gg427610.aspx" target="_blank">Bing 7.0</a></td>
<td style="padding:10px;">40</td>
<td style="padding:10px;"><span style="background-color:#468847;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">431.45</span></td>
<td style="padding:10px;"><span style="background-color:#468847;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">339.49 (30)</span></td>
<td style="padding:10px;">86.67 (6)</td>
</tr>
<tr style="background-color:#eee;">
<td style="padding:10px;"><a href="https://developers.google.com/maps/documentation/javascript/tutorial" target="_blank">Google v3</a></td>
<td style="padding:10px;"><span style="background-color:#b94a48;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">66</span></td>
<td style="padding:10px;"><span style="background-color:#b94a48;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">949.65</span></td>
<td style="padding:10px;"><span style="background-color:#b94a48;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">842.93 (54)</span></td>
<td style="padding:10px;"><span style="background-color:#b94a48;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">105.88 (12)</span></td>
</tr>
<tr>
<td style="padding:10px;"><a href="http://leaflet.cloudmade.com/reference.html" target="_blank">Leaflet 0.3.1 (Cloudmade)</a></td>
<td style="padding:10px;"><span style="background-color:#468847;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">30</span></td>
<td style="padding:10px;">603.23</td>
<td style="padding:10px;">513.56 (26)</td>
<td style="padding:10px;">81.52 (1)</td>
</tr>
<tr style="background-color:#eee;">
<td style="padding:10px;"><a href="http://developer.mapquest.com/web/documentation/sdk/javascript/v7.0" target="_blank">MapQuest 7.0</a></td>
<td style="padding:10px;">60</td>
<td style="padding:10px;">900.30</td>
<td style="padding:10px;"><span style="background-color:#b94a48;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">851.82 (53)</span></td>
<td style="padding:10px;"><span style="background-color:#468847;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">46.81 (4)</span></td>
</tr>
<tr>
<td style="padding:10px;"><a href="https://github.com/stamen/modestmaps-js/wiki" target="_blank">Modest Maps 1.0.0 beta (MapBox)</a></td>
<td style="padding:10px;">38</td>
<td style="padding:10px;">901.48</td>
<td style="padding:10px;"><span style="background-color:#b94a48;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">859.96 (35)</span></td>
<td style="padding:10px;"><span style="background-color:#468847;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">39.62 (1)</span></td>
</tr>
<tr style="background-color:#eee;">
<td style="padding:10px;"><a href="http://api.maps.ovi.com/devguide/overview.html" target="_blank">Nokia Ovi</a></td>
<td style="padding:10px;">48</td>
<td style="padding:10px;">523.87</td>
<td style="padding:10px;"><span style="background-color:#468847;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">372.47 (36)</span></td>
<td style="padding:10px;"><span style="background-color:#b94a48;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">150.16 (10)</span></td>
</tr>
<tr>
<td style="padding:10px;"><a href="http://docs.openlayers.org/" target="_blank">OpenLayers 2.11 Mobile</a></td>
<td style="padding:10px;">52</td>
<td style="padding:10px;">595.28</td>
<td style="padding:10px;">508.70 (48)</td>
<td style="padding:10px;">83.35 (1)</td>
</tr>
<tr>
<td style="padding:10px;font-size:8pt;" colspan="5">* Note:</p>
<ul>
<li>These pages were tested at 1024×768.</li>
<li>The KBs for documents and stylesheets were excluded.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<h2>Bing</h2>
<p>As we can see from the results, Microsoft&#8217;s <a href="http://www.bing.com/maps/" target="_blank">Bing Maps</a> is a good alternative that has improved a lot since version 6.3. In version 6.3, Bing quietly introduced a &#8220;core&#8221; version for mobile that stripped out features like drawing lines and polygons. This reduced their JavaScript library from 230 KB to 47 KB! Unfortunately, if you needed some of those features, you were out of luck. But in version 7.0, they cleaned up their API and reduced it to 87 KB (without stripping features). So when you combine that savings with Bing&#8217;s smaller tile size, the Bing test map transferred <span style="background-color:#468847;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">432 KB</span> — that&#8217;s less than half of Google Maps! So I could stop here and just tell you to use Bing instead, but (as you&#8217;ll see) it&#8217;s always good to look at other options&#8230;</p>
<h2>Modest Maps</h2>
<p>Especially if we look at the API with the smallest library, <a href="http://modestmaps.com/" target="_blank">Modest Maps</a>, is a new library that weighs in at only <span style="background-color:#468847;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">40 KB</span>! It was designed to be simple, extensible, and it even works in older browsers like IE7. However, it&#8217;s tile size was the largest at <span style="background-color:#b94a48;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">861 KB</span>!</p>
<h2>MapQuest</h2>
<p><a href="http://www.mapquest.com/" target="_blank">MapQuest</a> is a provider that has been around for a while. Their version 7.0 is the second-smallest library at only <span style="background-color:#468847;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">47 KB</span>, but their tile size is the third largest at <span style="background-color:#b94a48;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">852 KB</span>.</p>
<h2>Nokia Ovi</h2>
<p>So if we&#8217;re also looking for an API that has the smallest tile size, Bing looks like the best choice. <a href="http://maps.nokia.com/" target="_blank">Nokia&#8217;s Ovi</a> tiles are also lightweight at <span style="background-color:#468847;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">373 KB</span>, but their JavaScript library is the largest at <span style="background-color:#b94a48;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">151 KB</span>! It&#8217;s too bad we couldn&#8217;t use Modest Map&#8217;s compact library with Bing&#8217;s lightweight tiles&#8230;or can we? Well, in a way we can&#8230;</p>
<h2>OpenLayers</h2>
<p><a href="http://openlayers.org/" target="_blank">OpenLayers</a>, as the name suggests, is a completely free and Open Source library that allows you to switch between different base layers like Google Maps, Virtual Earth (Bing), Yahoo, etc. From a business model, this approach makes a lot of sense because it means you&#8217;re not tied to one mapping provider and you&#8217;re not as restricted by licensing or forced-API changes. With this approach, you can switch providers without having to completely change your code.</p>
<p>However, OpenLayers supports other maps by creating their own API layer <strong>on top</strong> of the other mapping APIs. So to use OpenLayers with Google or Bing, you&#8217;d have to include their libraries as well! This approach is fine for desktop, but it doesn&#8217;t make sense for mobile. Also, OpenLayers is not as well-documented as some of the others, and its API can be harder to learn. But, if you&#8217;re doing some serious GIS work, this is an API you&#8217;ll want to consider.</p>
<h2>Leaflet</h2>
<p>Fortunately, a new lightweight library called <a href="http://leaflet.cloudmade.com/index.html" target="_blank">Leaflet</a> has been gaining popularity because it is a modern Open Source library that uses HTML5 and CSS3. It was designed from the ground up to work in modern and mobile browsers. Since CSS3 is hardware-accelerated on many mobile devices, visuals like zooming and fading will be much faster than JavaScript-based animations.</p>
<p>Also, Leaflet has an easy-to-use API. So just how easy is it to add a map? First, we include the CSS and JavaScript:</p>
<pre class="prettyprint">                <code class="language-html"> &lt;link rel="stylesheet" href="leaflet.css"&gt; &lt;script type="text/javascript" src="leaflet.js"&gt;&lt;/script&gt; </code></pre>
<p>Then we create a new tile layer specifying the format of the tile URL with some options like maximum zoom level:</p>
<pre class="prettyprint">                <code class="language-js"> var tileUrl = "http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png", tileAttr = "Map data © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade", tileLayer = new L.TileLayer(tileUrl, { maxZoom: 18, attribution: tileAttr }); </code></pre>
<p>Then we create the map and add the tile layer to it:</p>
<pre class="prettyprint">                <code class="language-js"> var map = new L.Map("map", { center: new L.LatLng(43.6425778753, -79.3870621920), // Toronto zoom: 14 }); map.addLayer(tileLayer); </code></pre>
<p>That&#8217;s it! Like OpenLayers, Leaflet allows you to easily switch between tile providers, but it does this in a much cleaner way — all you have to do is change the tile URL. So you don&#8217;t even need to include a vendor&#8217;s API to use their tiles. Of course, if you do use another tile provider, make sure you contact them about licensing and include the proper attribution.</p>
<pre class="prettyprint">                <code class="language-js"> var tileUrl = "http://{s}.googleapis.com/vt?lyrs=m@174225136&amp;src=apiv3&amp;hl=en-US&amp;x={x}&amp;y={y}&amp;z={z}&amp;s=Galile&amp;style=api%7Csmartmaps", tileAttr = "Map data © 2012 Google", tileLayer = new L.TileLayer(tileUrl, { maxZoom: 22, subdomains: ['mt0', 'mt1'], attribution: tileAttr }); </code></pre>
<p>So with this simple approach, you can change the base tile layer to almost any provider as long as they are using OpenStreetMap&#8217;s <a href="http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames" target="_blank">&#8220;Slippy&#8221;</a> tile naming convention, which is pretty much every provider, except for Bing because Microsoft uses a different <a href="http://msdn.microsoft.com/en-us/library/bb259689.aspx" target="_blank">&#8220;Quadkey&#8221;</a> convention.</p>
<h2>Tile Naming Conventions</h2>
<p>Basically, Slippy uses a straight-forward naming convention that looks like this (&#8220;mustache-style&#8221; URL template):</p>
<pre>http://<span style="background-color:#ff0;">{s}</span>.tile.cloudmade.com/YOUR-API-KEY/997/256/<span style="background-color:#ff0;">{z}</span>/<span style="background-color:#ff0;">{x}</span>/<span style="background-color:#ff0;">{y}</span>.png</pre>
<p>where,</p>
<ul>
<li>{s} = subdomain</li>
<li>{x} = x-coordinate</li>
<li>{y} = y-coordinate</li>
<li>{z} = zoom level</li>
</ul>
<p>Here&#8217;s an example of an actual tile (near the CN Tower):</p>
<pre>http://<span style="background-color:#ff0;">b</span>.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/<span style="background-color:#ff0;">14</span>/<span style="background-color:#ff0;">4578</span>/<span style="background-color:#ff0;">5980</span>.png</pre>
<p>But if we compare Slippy to the Quadkey format, you&#8217;ll notice it&#8217;s different enough that we can&#8217;t easily use it (at least not with Leaflet — we can with Modest Maps):</p>
<pre>http://ecn.<span style="background-color:#ff0;">{s}</span>.tiles.virtualearth.net/tiles/<span style="background-color:#ff0;">{style}</span><span style="background-color:#ff0;">{quadkey}</span>?g=914&amp;mkt=en-us&amp;lbl=l1&amp;stl=h&amp;shading=hill&amp;n=z

http://ecn.<span style="background-color:#ff0;">t0</span>.tiles.virtualearth.net/tiles/<span style="background-color:#ff0;">r</span><span style="background-color:#ff0;">03022313122210</span>?g=914&amp;mkt=en-us&amp;lbl=l1&amp;stl=h&amp;shading=hill&amp;n=z</pre>
<p>because the Quadkey format works like this:</p>
<ul>
<li>At zoom level 1 (of the entire world), there are only 4 tiles (or quadrants) numbered from 0 to 3. At the next zoom level, each tile is sub-divided into &#8220;quads&#8221;, and so on.</li>
<li>So the length of the quadkey represents the number of zoom levels.</li>
<li>The quadkey of any tile starts with the quadkey of its parent tile.</li>
<li>The first letter (which is not really part of the quadkey) specifies the base map style (r = Road, a = Aerial (Satellite), h = Hybrid (Aerial + Labels)</li>
</ul>
<p><a href="http://rimdevblog.files.wordpress.com/2012/05/ic962381.jpg"><img class="aligncenter size-full wp-image-9345" title="IC96238" src="http://rimdevblog.files.wordpress.com/2012/05/ic962381.jpg?w=623&#038;h=365" alt="TITLE_IMAGE" width="623" height="365" /></a></p>
<figure>
<figcaption><a href="http://msdn.microsoft.com/en-us/library/bb259689.aspx" target="_blank">&#8220;Bing Maps Tile System&#8221;</a></figcaption>
</figure>
<p>Although it might be tempting to complain about Microsoft being different, from a database perspective, quadkeys makes indexing and storage really efficient.</p>
<h2>Hybrid Approach</h2>
<p>Hopefully, that gives you a better understanding of tile structures. Do you see the possibilities? This is AWESOME! This means we can easily interchange libraries and tiles to suit our needs. Essentially, we can build our own &#8220;hybrid&#8221; API or &#8220;mashup&#8221; from the best pieces available. So now we can have an API that uses Bing&#8217;s tiles, but is even <strong>lighter</strong> than Bing itself (which was already light to begin with at 432 KB)!</p>
<p>Here are some other combinations that are under 450 KB that you may want to consider:</p>
<table style="border:1px solid #DDD;border-radius:10px;">
<tbody>
<tr style="background-color:#000;color:#fff;">
<td style="padding:10px;text-align:center;">API Provider</td>
<td style="padding:10px;text-align:center;">Requests</td>
<td style="padding:10px;text-align:center;">Transferred<br />
(KB)</td>
<td style="padding:10px;text-align:center;">Images<br />
(KB)</td>
<td style="padding:10px;text-align:center;">Scripts<br />
(KB)</td>
</tr>
<tr>
<td style="padding:10px;">Modest Maps 1.0.0 beta + Bing Tiles</td>
<td style="padding:10px;">38</td>
<td style="padding:10px;"><span style="background-color:#468847;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">380.51</span></td>
<td style="padding:10px;">338.97 (35)</td>
<td style="padding:10px;">39.62 (1)</td>
</tr>
<tr style="background-color:#eee;">
<td style="padding:10px;">Modest Maps 1.0.0 beta + Nokia Tiles</td>
<td style="padding:10px;">38</td>
<td style="padding:10px;"><span style="background-color:#468847;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">412.41</span></td>
<td style="padding:10px;">370.93 (35)</td>
<td style="padding:10px;">39.62 (1)</td>
</tr>
<tr>
<td style="padding:10px;">Leaflet 0.3.1 + Nokia Tiles</td>
<td style="padding:10px;">30</td>
<td style="padding:10px;"><span style="background-color:#468847;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">431.78</span></td>
<td style="padding:10px;">342.09 (26)</td>
<td style="padding:10px;">81.52 (1)</td>
</tr>
</tbody>
</table>
<p>Since we were able to make Bing lighter, I was curious to see if we could do the same with Google, and the result really surprised me! As you may recall, Google Maps transferred <strong>950 KB</strong>, but when I combined Leaflet with Google&#8217;s tiles, it only transferred <strong>498 KB</strong>! That&#8217;s half the size, which is great! But why such a difference?! Well, if we look at the number of requests, it gives us a big clue — Google&#8217;s API is loading <strong>twice</strong> the number of tiles!</p>
<table style="border:1px solid #DDD;border-radius:10px;">
<tbody>
<tr style="background-color:#000;color:#fff;">
<td style="padding:10px;text-align:center;">API Provider</td>
<td style="padding:10px;text-align:center;">Requests</td>
<td style="padding:10px;text-align:center;">Transferred<br />
(KB)</td>
<td style="padding:10px;text-align:center;">Images<br />
(KB)</td>
<td style="padding:10px;text-align:center;">Scripts<br />
(KB)</td>
</tr>
<tr>
<td style="padding:10px;">Google v3</td>
<td style="padding:10px;">66</td>
<td style="padding:10px;">949.65</td>
<td style="padding:10px;">842.93 (54)</td>
<td style="padding:10px;">105.88 (12)</td>
</tr>
<tr style="background-color:#eee;">
<td style="padding:10px;">Leaflet 0.3.1 + Google Tiles</td>
<td style="padding:10px;">30</td>
<td style="padding:10px;">497.71</td>
<td style="padding:10px;">408.01 (26)</td>
<td style="padding:10px;">81.52 (1)</td>
</tr>
<tr>
<td style="padding:10px;"><strong>Difference:</strong></td>
<td style="border-top:2px solid #000;"><span style="background-color:#b94a48;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">36</span></td>
<td style="border-top:2px solid #000;"><span style="background-color:#b94a48;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">451.94</span></td>
<td style="border-top:2px solid #000;"><span style="background-color:#b94a48;color:#fff;font-weight:bold;padding-left:10px;padding-right:10px;border-radius:15px;">434.92</span></td>
<td style="border-top:2px solid #000;">24.36</td>
</tr>
</tbody>
</table>
<p>At first, I thought it might be pre-fetching or &#8220;lazy loading&#8221; tiles for areas outside the bounding box in case a user pans or zooms. But when I inspected the extra tiles, I found it&#8217;s actually loading another set of tiles for the <strong>same area</strong>, which I haven&#8217;t been able to figure out why — the extra tiles don&#8217;t seem to be displayed anywhere. It&#8217;s still a map view tile, but it has slightly different labels. Notice the one on the right has &#8220;Corktown&#8221; and the other one doesn&#8217;t?</p>
<table style="border:1px solid #DDD;border-radius:10px;">
<tbody>
<tr>
<td style="padding:10px;text-align:center;font-weight:bold;">Tile Set 1 (displayed)</td>
<td style="padding:10px;text-align:center;font-weight:bold;">Tile Set 2 (not displayed)</td>
</tr>
<tr>
<td style="padding:10px;font-size:8pt;"><span style="background-color:#ff0;"><a href="http://rimdevblog.files.wordpress.com/2012/05/vt_dvp_gardiner1_circle.png"><img class="aligncenter size-full wp-image-9347" title="vt_dvp_gardiner1_circle" src="http://rimdevblog.files.wordpress.com/2012/05/vt_dvp_gardiner1_circle.png?w=256&#038;h=256" alt="" width="256" height="256" /></a>m@174232040</span>&amp;src=apiv3&amp;hl=en-US&amp;x=4580&amp;y=5979</p>
<p>&amp;z=14</p>
<p>&amp;s=Galileo</p>
<p>&amp;style=api%7Csmartmaps</td>
<td style="padding:10px;font-size:8pt;"><span style="background-color:#ff0;"><a href="http://rimdevblog.files.wordpress.com/2012/05/vt_dvp_gardiner2_circle.png"><img class="aligncenter size-full wp-image-9348" title="vt_dvp_gardiner2_circle" src="http://rimdevblog.files.wordpress.com/2012/05/vt_dvp_gardiner2_circle.png?w=256&#038;h=256" alt="" width="256" height="256" /></a>m@174000000</span>&amp;src=apiv3&amp;hl=en-US&amp;x=4580&amp;y=5979</p>
<p>&amp;z=14</p>
<p>&amp;s=Galileo</p>
<p>&amp;style=api%7Csmartmaps</td>
</tr>
</tbody>
</table>
<p>I&#8217;m sure there&#8217;s a good reason for this, but I&#8217;d be curious if there&#8217;s an option to disable that? Either way, the good news is Google&#8217;s tiles are not as heavy as I first thought so we can use them with Modest Maps or Leaflet to build familiar-looking mapping applications that will be more lightweight especially for mobile.</p>
<p>Besides being able to switch between providers, this hybrid approach has other advantages:</p>
<ol>
<li>For packaged applications like <a href="https://bdsc.webapps.blackberry.com/html5/" target="_blank">BlackBerry® WebWorks™</a>, you can locally include the required API files (JavaScript, CSS, and images) with your application so you don&#8217;t need to fetch them from a remote server. This makes loading an app faster and reduces bandwidth charges.</li>
<li>Another advantage of having local files is you don&#8217;t have to worry as much about a provider forcing an API change that can break your customizations. Although, you can usually reference an older API, sometimes a provider will force an upgrade even if you try to reference an older version.</li>
<li>In the case of Yahoo! Maps, which discontinued its map service in September 2011, a local version means your app can still work. For example, Leaflet provides a layer control so you can select from different base layers.</li>
</ol>
<p>These advantages are important especially for enterprise or mission-critical applications that need to minimize risk and downtime. So in the next post, I&#8217;ll cover some techniques for adding offline capabilities to your map. Hopefully, with this &#8220;best of breed&#8221; approach, you&#8217;ll be ready to build a map-based app that will feel more like a paper airplane than a paper ball.</p>
<div style="text-align:center;"><a href="http://rimdevblog.files.wordpress.com/2012/05/origami_sm1.png"><img class="aligncenter size-full wp-image-9349" title="origami_sm" src="http://rimdevblog.files.wordpress.com/2012/05/origami_sm1.png?w=140&#038;h=80" alt="" width="140" height="80" /></a></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/9328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/9328/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=9328&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2012/05/lightweight-maps-for-mobile-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/01266d01d1ae9a95d889f5143acd2a49?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">myjing</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2012/05/sheet_sm.png" medium="image">
			<media:title type="html">sheet_sm</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2012/05/crumpled_sm.png" medium="image">
			<media:title type="html">crumpled_sm</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2012/05/origami_sm.png" medium="image">
			<media:title type="html">origami_sm</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2012/05/ic962381.jpg" medium="image">
			<media:title type="html">IC96238</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2012/05/vt_dvp_gardiner1_circle.png" medium="image">
			<media:title type="html">vt_dvp_gardiner1_circle</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2012/05/vt_dvp_gardiner2_circle.png" medium="image">
			<media:title type="html">vt_dvp_gardiner2_circle</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2012/05/origami_sm1.png" medium="image">
			<media:title type="html">origami_sm</media:title>
		</media:content>
	</item>
	</channel>
</rss>
