You Are Here:

Community: Wiki

This page was last modified on 26 January 2009, at 10:48.

CS001285 - Adding a landmark in Flash Lite

From Forum Nokia Wiki



ID CS001285 Creation date January 26, 2009
Platform S60 5th Edition Tested on devices Nokia 5800 XpressMusic
Category Flash Lite Subcategory Location


Keywords (APIs, classes, methods, functions): Service.Location, location.Trace(), location.CancelNotification(), Service.Landmarks, landmark.Add()

Overview

This code snippet demonstrates how to track movements and save the location information as a landmark using the Location and Landmarks Platform Services for Flash Lite supported from S60 5th Edition onwards.

Preconditions

Note: To get the location data the GPS of the device needs to be active. If GPS does not work it is possible to set the information to the input.

Source

// Import Platform Service Interface
import com.nokia.lib.Service;
// Heading of the application
heading_txt.text = "Adding a landmark";
 
// Create new Service object which has Location information
var location = new Service("Service.Location", "ILocation");
 
// Create new Service object which has Landmark information
var landmark = new Service("Service.Landmarks", "IDataSource");
 
/**********************************************************
** Function for pressing the Track button.
** Calls Trace() method asynchronously.
** Traces location information to the text field.
**********************************************************/

track_mc.onPress = function() {
 
error_txt.text = "Waiting for GPS";
 
// Disable button because an asynchronous method cannot be called twice
track_mc.enabled = false;
 
// Define input parameters
// 1000000 microseconds = 1 second (update interval)
var updateOptions = {UpdateInterval:1000000};
var inParams = {LocationInformationClass:"GenericLocationInfo",
Updateoptions:updateOptions};
 
// Call Trace() as an asynchronous method
location.Trace(inParams,onNotify);
 
// Define callback function
function onNotify (transactionID:Number, eventID:String, outParam:Object) {
if (outParam.ErrorCode == 0) {
var outList = outParam.ReturnValue;
var longitude = outList.Longitude;// Contains longitudinal data
var latitude = outList.Latitude;// Contains latitudinal data
longitude_txt.text = longitude
latitude_txt.text = latitude;
} else {
var errorId = outParam.ErrorCode;
error_txt.text = "Error while tracking: "+errorId;
};
};
};
 
/**********************************************************
** Function for pressing the Stop button.
** Calls CancelNotification() method synchronously.
** Method cancels the Trace method
**********************************************************/

stop_mc.onPress = function() {
 
// Define input parameters
var inParams = {CancelRequestType:"TraceCancel"};
 
// Define result value
var outParams = location.CancelNotification(inParams);
if (outParams.ErrorCode == 0) {
error_txt.text = "Trace stopped."
} else {
var errorId2 = outParams.ErrorCode;
error_txt.text = "Error while stopping: "+errorId2;
};
 
// Enable Track button
track_mc.enabled = true;
};
 
/**********************************************************
** Function for pressing the Add button.
** Calls Add() method synchronously.
** Adds a new landmark with name and position information.
**********************************************************/

add_mc.onPress = function() {
 
// Get info from the inputs
var landmarkName = landmark_txt.text;
var lon = longitude_txt.text;
var lat = latitude_txt.text;
var longitude = Number(lon);
var latitude = Number(lat);
 
// Define landmark information
var landmarkPosition = {Longitude:longitude, Latitude:latitude};
var landmarkInfo = {LandmarkName:landmarkName,
LandmarkPosition:landmarkPosition};
 
// Define input parameters
var inParams = {Type:"Landmark", Data:landmarkInfo};
 
// Define result value
var outParams = landmark.Add(inParams);
if (outParams.ErrorCode == 0) {
var landmarkId = outParams.ReturnValue;
error_txt.text = "ID"+landmarkId+" added";
}
else {
var errorId3 = outParams.ErrorCode;
error_txt.text = "Error while adding: "+errorId3;
};
};

Postconditions

When the Track button is pressed, longitude and latitude information of the device are displayed as inputs. Location information on the screen changes when the device moves. Tracking can be stopped by pressing the Stop button. You can add a landmark by pressing the Add button when Landmark, longitude, and latitude inputs have data.

Example application

The following sample application has been tested in the Nokia 5800 XpressMusic (S60 5th Edition, Flash Lite 3.0). File:FlashLite Adding A Landmark.zip

See also

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fFlashE5fE4citeE5fAPIE5fBridgeE5fInterfaceX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZflashQ qfnZtopicQUqfnTopicZflashE5fliteQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ