<?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>Jappit.com &#187; google static maps</title>
	<atom:link href="http://www.jappit.com/blog/tag/google-static-maps/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jappit.com/blog</link>
	<description>Mobile blog by Alessandro La Rosa</description>
	<lastBuildDate>Wed, 23 Nov 2011 10:38:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Displaying GPS position in FlashLite using Google Static Maps and KuneriLite</title>
		<link>http://www.jappit.com/blog/2008/06/12/displaying-gps-position-in-flashlite-using-google-static-maps-and-kunerilite/</link>
		<comments>http://www.jappit.com/blog/2008/06/12/displaying-gps-position-in-flashlite-using-google-static-maps-and-kunerilite/#comments</comments>
		<pubDate>Thu, 12 Jun 2008 12:46:14 +0000</pubDate>
		<dc:creator>pit</dc:creator>
				<category><![CDATA[flash lite]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[forumnokia]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[google static maps]]></category>
		<category><![CDATA[gps]]></category>
		<category><![CDATA[kunerilite]]></category>
		<category><![CDATA[localization]]></category>

		<guid isPermaLink="false">http://www.jappit.com/blog/?p=49</guid>
		<description><![CDATA[Today&#8217;s tutorial is about using Google Maps static images, and GPS data, to display maps in a FlashLite application using KuneriLite. Prerequisites Get your own Google Maps API key To use Google Maps services, you should have a Google Maps API key. If you do not have one, you can go here: http://code.google.com/apis/maps/signup.html and signup [...]]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s tutorial is about using <a title="Google Static Maps documentation" href="http://code.google.com/apis/maps/documentation/staticmaps/" target="_blank">Google Maps static images</a>, and GPS data, to display maps in a <a title="FlashLite website" href="http://www.adobe.com/products/flashlite/" target="_blank">FlashLite</a> application using <a title="KuneriLite website" href="http://www.kunerilite.net" target="_blank">KuneriLite</a>.</p>
<p><img src="http://www.jappit.com/images/blog/uploads/kuneri_maps_screenshot.jpg" alt="FlashLite KuneriLite Google Maps application screenshot" width="333" height="291" /></p>
<h3>Prerequisites</h3>
<h4>Get your own Google Maps API key</h4>
<p>To use Google Maps services, you should have a <strong>Google Maps API key</strong>. If you do not have one, you can go here:</p>
<p><a title="Google Maps API key signup page" href="http://code.google.com/apis/maps/signup.html" target="_blank">http://code.google.com/apis/maps/signup.html</a></p>
<p>and signup for your API key.</p>
<h4>Download and install KuneriLite</h4>
<p><strong><a title="KuneriLite website" href="http://www.kunerilite.net" target="_blank">KuneriLite</a> </strong>is a tookit that <strong>extends FlashLite capabilites</strong> allowing applications to access <strong>native Symbian functionalities</strong>, like file writing, or reading <strong>GPS data</strong>.</p>
<p>To proceed in this tutorial, you must download and install KuneriLite: <a title="KuneriLite download page" href="http://www.kunerilite.net/content/view/33/47/" target="_blank">KuneriLite download page</a>.</p>
<h3>Create FlashLite application</h3>
<h4>Create your FlashLite movie</h4>
<p>In this example, we&#8217;ll use FlashLite 2.1, but porting it to other (older or newer) FlashLite versions will be quite straightforward. So, after you&#8217;ve created an empty FlashLite movie, follow this simple steps:</p>
<ul>
<li><strong> Create a Button</strong> by going to <em>Insert -&gt; New Symbol&#8230;</em></li>
<li> enter <strong>GpsButton as name</strong></li>
<li> check the <strong>Export for ActionScript</strong> and <strong>Export in first frame checkboxes</strong></li>
</ul>
<p><img src="http://www.jappit.com/images/blog/uploads/gpsButtonProperties.jpg" alt="GpsButton properties" width="429" height="330" /></p>
<ul>
<li> Now, design your Button as you prefer, for example placing a big <strong>&#8220;Find me!&#8221; label</strong> on it</li>
<li> After you&#8217;ve finished designing your Button, place it on movie root, in the lower part of the stage, as in the attached screenshot, and give it <strong>startButton as Instance Name</strong></li>
</ul>
<p><img src="http://www.jappit.com/images/blog/uploads/buttonOnStage.jpg" alt="Place GpsButton on stage" width="295" height="350" /></p>
<h4>Enter ActionScript code</h4>
<p>On movie root, <strong>create a new layer called Actions</strong>, and open its ActionScript editor. We&#8217;ll start defining some properties:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// Enter your api key here</span>
<span style="color: #000000; font-weight: bold;">var</span> apiKey = <span style="color: #ff0000;">'API_KEY'</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//If you're using non-commercial version of KuneriLite, you'll not need to change this</span>
<span style="color: #000000; font-weight: bold;">var</span> kuneriPath = <span style="color: #ff0000;">'http://127.0.0.1:1001/Basic/'</span>;</pre></div></div>

<p>Now, we&#8217;ll define some useful functions that we&#8217;ll use in our code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//We'll call this function when some KuneriLite related errors occur</span>
<span style="color: #000000; font-weight: bold;">function</span> kuneriError<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">error</span>:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;KuneriLite error: &quot;</span> + <span style="color: #0066CC;">error</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//This function will do all calls to KuneriLite servers</span>
<span style="color: #808080; font-style: italic;">//and call the given handler passing response values as argument</span>
<span style="color: #000000; font-weight: bold;">function</span> kuneriLoad<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span>, handler<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> loader:<span style="color: #0066CC;">LoadVars</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">LoadVars</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	loader.<span style="color: #0066CC;">onLoad</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		handler<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;LOADING: &quot;</span> + <span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	loader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Now, let&#8217;s code the Button-related logic. When the user presses the <strong>startButton </strong>we want to:</p>
<ul>
<li> start the GPS</li>
<li> retrieve the current GPS position</li>
<li> display a map centered in the retrieved GPS position</li>
</ul>
<p>To get full infos about about KuneriLite GPS plugin, you can check the related Wiki page: <a title="KuneriLite GPS plugin Wiki page" href="http://wiki.kunerilite.net/index.php?title=GPS_plugin" target="_blank">http://wiki.kunerilite.net/index.php?title=GPS_plugin</a></p>
<p>We begin starting the GPS on gpsButton press, using the <strong>start klCommand</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">startButton.<span style="color: #0066CC;">onPress</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	kuneriLoad<span style="color: #66cc66;">&#40;</span>kuneriPath + <span style="color: #ff0000;">'GPS?klCommand=start'</span>, gpsStarted<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> gpsStarted<span style="color: #66cc66;">&#40;</span>res:<span style="color: #0066CC;">LoadVars</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>res.<span style="color: #006600;">klError</span> == <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">||</span> res.<span style="color: #006600;">klError</span> == -<span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;GPS started&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		kuneriLoad<span style="color: #66cc66;">&#40;</span>kuneriPath + <span style="color: #ff0000;">'GPS?klCommand=read'</span>, gpsDataRead<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #66cc66;">&#123;</span>
		kuneriError<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Error starting GPS!&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The <strong>gpsStarted() </strong>handler will:</p>
<ul>
<li> check if there is no error (<strong>klError = 0</strong>) or if GPS is already started (<strong>klError = -11</strong>). For full errors list associated with GPS plugin, check KuneriLite Wiki page:<a title="KuneriLite GPS plugin Wiki page" href="http://wiki.kunerilite.net/index.php?title=GPS_plugin" target="_blank"> <a href="http://wiki.kunerilite.net/index.php?title=GPS_plugin" rel="nofollow">http://wiki.kunerilite.net/index.php?title=GPS_plugin</a></a></li>
<li> if there&#8217;s an error starting the GPS, call our kuneriError() function defined above</li>
<li> if GPS is correctly started, it will make a second call to KuneriLite, this time to retrieve current GPS position (<strong>klCommand=read</strong>)</li>
</ul>
<p>This second call to KuneriLite will call <strong>gpsDataRead() handler</strong>, defined below:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> gpsDataRead<span style="color: #66cc66;">&#40;</span>res:<span style="color: #0066CC;">LoadVars</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>res.<span style="color: #006600;">klError</span> == <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>res.<span style="color: #006600;">klPosLatitude</span> <span style="color: #66cc66;">!</span>= <span style="color: #0066CC;">undefined</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> lat = res.<span style="color: #006600;">klPosLatitude</span>;
			<span style="color: #000000; font-weight: bold;">var</span> lng = res.<span style="color: #006600;">klPosLongitude</span>;
&nbsp;
			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;POSITION: &quot;</span> + lat + <span style="color: #ff0000;">&quot;, &quot;</span> + lng<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			loadMap<span style="color: #66cc66;">&#40;</span>lat, lng<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #66cc66;">&#123;</span>
			kuneriLoad<span style="color: #66cc66;">&#40;</span>kuneriPath + <span style="color: #ff0000;">'GPS?klCommand=read'</span>, gpsDataRead<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #66cc66;">&#123;</span>
		kuneriError<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Error retrieving GPS position!&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This handler, as above, will check if there is any error raised by KuneriLite and, if not, will check if latitude and longitude coordinates are available, by checking response <strong>klPosLatitude and klPosLongitude property</strong> values. If they&#8217;re not available, a new call to <strong>read klCommand</strong> is done, otherwise the following <strong>loadMap()</strong> function is called.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> loadMap<span style="color: #66cc66;">&#40;</span>lat:<span style="color: #0066CC;">Number</span>, lng:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> mapClip:<span style="color: #0066CC;">MovieClip</span> = <span style="color: #0066CC;">_root</span>.<span style="color: #0066CC;">createEmptyMovieClip</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'mapClip'</span>, <span style="color: #0066CC;">_root</span>.<span style="color: #0066CC;">getNextHighestDepth</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	mapClip.<span style="color: #0066CC;">_x</span> = <span style="color: #cc66cc;">0</span>;
	mapClip.<span style="color: #0066CC;">_y</span> = <span style="color: #cc66cc;">0</span>;
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> mapWidth = <span style="color: #cc66cc;">240</span>;
	<span style="color: #000000; font-weight: bold;">var</span> mapHeight = <span style="color: #cc66cc;">280</span>;
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> loader:<span style="color: #0066CC;">MovieClipLoader</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">MovieClipLoader</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> mapUrl:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">'http://maps.google.com/staticmap?center='</span> +
		lat + <span style="color: #ff0000;">','</span> + lng + <span style="color: #ff0000;">'&amp;amp;format=jpg&amp;amp;zoom=8&amp;amp;size='</span> +
		mapWidth + <span style="color: #ff0000;">'x'</span> + mapHeight + <span style="color: #ff0000;">'&amp;amp;key='</span> + apiKey;
&nbsp;
	loader.<span style="color: #0066CC;">loadClip</span><span style="color: #66cc66;">&#40;</span>mapUrl, mapClip<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The above function:</p>
<ul>
<li> attaches a <strong>new empty movie clip </strong>to movie root</li>
<li> places it to coordinates (0,0)</li>
<li> use a <strong>MovieClipLoader </strong>to load a 240&#215;280 map image, in jpeg format, in the empty clip</li>
</ul>
<p>Done that, you can actually test your FlashLite movie</p>
<h3>Test your FlashLite application</h3>
<h4>Test on PC</h4>
<p>To test your application without deploying on real device, you must follow these simple steps:</p>
<ul>
<li> <strong>Start KuneriLite emulator</strong> with default settings (port: 1001, key: Basic)</li>
<li><strong> Start your FlashLite movie</strong></li>
<li> <strong>Press Find Me!</strong> and wait for your image to be loaded (of course, being an emulator, the GPS position will be not real <img src='http://www.jappit.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )</li>
</ul>
<p>For more infos about KuneriLite Emulator, you can go here: <a title="KuneriLite Emulator Wiki page" href="http://wiki.kunerilite.net/index.php?title=KuneriLite_Emulator" target="_blank">KuneriLite Emulator Wiki page</a></p>
<h4>Test on real device</h4>
<p>To test your app on real device, you must package your SIS application using KuneriLite Wizard, following these steps:</p>
<p><img src="http://www.jappit.com/images/blog/uploads/kunerimaps_wizard_shot.jpg" alt="KuneriLite Emulator screenshot" /></p>
<ul>
<li><strong> Export</strong> your FlashLite movie</li>
<li> Create a <strong>new KuneriLite project</strong></li>
<li> Enter application name and other data, <strong>checking GPS from the available plugins</strong></li>
<li> Check <strong>&#8220;Use external player&#8221;</strong> option if you developed for a development player (2.x or 3.x) and would like to launch the application using one of those players</li>
<li> It is also recommended to always check <strong>&#8220;Use stub&#8221;</strong> option</li>
<li> Select the exported SWF as project Main SWF</li>
</ul>
<p><strong>Note</strong>: to use GPS you should sign your application, specifying certificate, key and password in KuneriLite Wizard interface. Otherwise, your application will not be able to access GPS functionalities.</p>
<p>For more infos about KuneriLite Wizard, you can go here: <a title="KuneriLite Wizard Beginner's Guide" href="http://wiki.kunerilite.net/index.php?title=KuneriLite_Wizard_Beginner%27s_Guide" target="_blank">KuneriLite Wizard Beginner&#8217;s Guide</a></p>
<h3>Source code and resources</h3>
<ul>
<li>Download the FLA source of this tutorial here: <a title="KuneriLite FlashLite GoogleMaps application source code" href="http://www.jappit.com/uploads/src/KuneriGpsMap.zip">KuneriGpsMap.zip</a> (the downloadable version includes some code that could be useful to debug possible problems)</li>
<li>For further resources about using Google Maps in mobile applications, you can check this other article: <a title="How to use Google Maps data in mobile applications" href="http://wiki.forum.nokia.com/index.php/How_to_use_Google_Maps_data_in_mobile_applications" target="_blank">How to use Google Maps data in mobile applications</a></li>
<li>This article is available also on Forum Nokia Wiki: <a title="FlashLite Google Maps article on Forum Nokia Wiki" href="http://wiki.forum.nokia.com/index.php/Displaying_GPS_position_using_Google_Maps_images_in_FlashLite" target="_blank">Displaying GPS position using Google Maps images in FlashLite</a></li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://www.jappit.com/blog/2008/06/12/displaying-gps-position-in-flashlite-using-google-static-maps-and-kunerilite/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

