You Are Here:

Community: Wiki

This page was last modified 15:37, 23 February 2009.

Displaying GPS position using Google Maps images in Flash Lite

From Forum Nokia Wiki

This article shows how to display current phone GPS position using Flash Lite, KuneriLite, and Google Static Maps. Image:Kuneri_maps_screenshot.jpg

Contents

Prerequisites

Get your own Google Maps API key

NOTE: Usage of this code with the free Google Maps API Key breaks Google's Terms and Conditions (section 10.8). You should purchase an Enterprise License if you wish to use the Google Maps API as shown in this example.

To use Google Maps services, you need a Google Maps API key. If you do not have one, you can sign up for a key here: http://code.google.com/apis/maps/signup.html

Download and install KuneriLite

KuneriLite is a toolkit that extends Flash Lite capabilites, allowing applications to access native Symbian OS functionalities, such as file writing or reading GPS data.
To proceed in this tutorial, download and install KuneriLite from the KuneriLite download page.

Create the Flash Lite application

Create your Flash Lite movie

In this example, Flash Lite 2.1 is used. However, porting it to other (older or newer) Flash Lite versions is quite straightforward. So, after you have created an empty Flash Lite movie, do as follows:

  • Create a button by going to Insert > New Symbol... and entering these properties:
    • Enter GpsButton as the name.
    • Mark the Export for ActionScript and Export in first frame check boxes.

Image:gpsButtonProperties.jpg

  • Design the button. You can, for example, place a big "Find me!" label on it.
  • After you have designed the button, place it in the movie root, in the lower part of the stage as in the attached screenshot, and give startButton as the Instance Name.

Image:buttonOnStage.jpg

Enter ActionScript code

In the movie root, create a new layer called Actions, and open its ActionScript editor. First define the properties:

// Enter your api key here
var apiKey = 'API_KEY';
 
//If you use the non-commercial version of KuneriLite, you do not need to change this
var kuneriPath = 'http://127.0.0.1:1001/Basic/';

Next, define some useful functions to be used in the code:

//This function is called when some KuneriLite-related errors occur
function kuneriError(error:String)
{
	trace("KuneriLite error: " + error);
}
 
//This function will do all calls to KuneriLite servers
//and call the given handler passing response values as the argument
function kuneriLoad(url, handler)
{
	var loader:LoadVars = new LoadVars();
	
	loader.onLoad = function()
	{
		handler(this);
	}
	trace("LOADING: " + url);
	
	loader.load(url);
}

Next, code the button-related logic. When the user presses startButton, the application should:

  • Start the GPS.
  • Retrieve the current GPS position.
  • Display a map centered in the retrieved GPS position.

To get full information about the KuneriLite GPS plug-in, check the related Wiki page:http://wiki.kunerilite.net/index.php?title=GPS_plugin The GPS is started when the gpsButton is pressed, using the start klCommand:

startButton.onPress = function()
{
	kuneriLoad(kuneriPath + 'GPS?klCommand=start', gpsStarted);
}
function gpsStarted(res:LoadVars)
{
	if(res.klError == 0 || res.klError == -11)
	{
		trace("GPS started");
		
		kuneriLoad(kuneriPath + 'GPS?klCommand=read', gpsDataRead);
	}
	else
	{
		kuneriError("Error starting GPS!");
	}
}

The gpsStarted() handler will:

  • Check that there are no errors (klError = 0) or if the GPS is already started (klError = -11). For a full list of errors associated with the GPS plug-in, check the KuneriLite Wiki page:

http://wiki.kunerilite.net/index.php?title=GPS_plugin

  • If there is an error in starting the GPS, call the kuneriError() function defined above.
  • If the GPS is started correctly, it will make a second call to KuneriLite, this time to retrieve the current GPS position (klCommand=read)

The second call to KuneriLite will call the gpsDataRead() handler defined below:

function gpsDataRead(res:LoadVars)
{
	if(res.klError == 0)
	{
		var lat = res.klPosLatitude;
		var lng = res.klPosLongitude;
		
		trace("POSITION: " + lat + ", " + lng);
		
		loadMap(lat, lng);
	}
	else
	{
		kuneriError("Error starting GPS!");
	}
}

This handler, as above, checks if there are any errors raised by KuneriLite and if not, extracts latitute and longidute coordinates from the response's klPosLatitude and klPosLongitude properties. After this, it calls the loadMap() function that actually loads the static map image.

function loadMap(lat:Number, lng:Number)
{
	var mapClip:MovieClip = _root.createEmptyMovieClip('mapClip', _root.getNextHighestDepth());
	
	mapClip._x = 0;
	mapClip._y = 0;
	
	var mapWidth = 240;
	var mapHeight = 280;
	
	var loader:MovieClipLoader = new MovieClipLoader();
	
	var mapUrl:String = 'http://maps.google.com/staticmap?center=' + 
		lat + ',' + lng + '&format=jpg&zoom=8&size=' + 
		mapWidth + 'x' + mapHeight + '&key=' + apiKey;
	
	loader.loadClip(mapUrl, mapClip);
}

The above function:

  • Attaches a new empty movie clip to the movie root.
  • Places it to coordinates (0,0).
  • Uses a MovieClipLoader to load a 240x280 pixel map image in JPEG format in the empty clip.

After this, you can actually test your Flash Lite movie.

Test your Flash Lite application

Test on PC

To test your application without deploying it on a real device:

  • Start the KuneriLite emulator with the default settings (port: 1001, key: Basic).
  • Start your FlashLite movie.
  • Press Find Me! and wait for your image to load (the GPS position is, of course not real when testing on the emulator :))

For more information about the KuneriLite emulator, see KuneriLite Emulator

Test on a real device

To test your application on a real device, package your SIS application using the KuneriLite Wizard: Image:Kunerimaps_wizard_shot.jpg

  • Export your FlashLite movie.
  • Create a new KuneriLite project.
  • Enter the application name and other data. Select GPS from the available plug-ins.
  • Select the "Use external player" option if you are developing for a development player (2.x or 3.x) and would like to launch the application using one of those players.
  • It is also recommended to always select the "Use stub" option.
  • Select the exported SWF as project Main SWF.

For more information about KuneriLite Wizard, see the KuneriLite Wizard Beginner's Guide.

Resources

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditFurlTechnocratiMagnoliaTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fOE78ygenE5fE2dE5fTheE5fFlashE5fE4citeE5fE44evelopersE5fKitX qdcZpublisherQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fidE2fc764fd1cE2d8b06E2d499aE2d9a6aE2d17c3903d5a65E2fforumE5fnokiaE5fcrawlerE5fagentX qdcZtitleQSxOE78ygenE20E2dE20TheE20FlashE20E4citeE20E44evelopersE20KitE20E2dE20ForumE20NokiaE20WikiX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfnTypeZCommunityContentQ qdcZtypeQUqfnTypeZE52esourceQ qdcZtypeQUqfnTypeZWebpageQ qdcZtypeQUqfnTypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qrssZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qfnZdistributionQUxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2fX qfnZtopicQUqfnTopicZflashQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZflashE5fliteQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtypeQUqfnTypeZCommunityContentQ qfnZtypeQUqfnTypeZE52esourceQ qfnZtypeQUqfnTypeZWebpageQ qfnZtypeQUqfnTypeZWikiContentQ qfnZupdatedQDx2008E2d10E2d03X qfnZuserE5ftagQSxflashX qfnZuserE5ftagQSxflashE2dliteX qmarsZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfnTypeZCommunityContentQ qrdfZtypeQUqfnTypeZE52esourceQ qrdfZtypeQUqfnTypeZWebpageQ qrdfZtypeQUqfnTypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ