| 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() |
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.
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.
// 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;
};
};
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.
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
No related wiki articles found