Archived:Modifying landmarks in Flash Lite
Article Metadata
Code Example
Source file: Media:FlashLite Modifying Landmarks.zip
Tested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 5th Edition
Article
Keywords: Service.Landmarks, landmark.GetList(), landmark.Add(), landmark.Delete()
Created: User:Nokia Developer KB
(26 Jan 2009)
Last edited: hamishwillee
(01 Aug 2012)
Contents |
Overview
This code snippet demonstrates how to list, edit, and delete Landmarks using the Landmarks Platform Service for Flash Lite supported from S60 5th Edition onwards.
Preconditions
Note: To modify landmarks, the test device needs to have at least one landmark registered.
Source
// Import Platform Service Interface
import com.nokia.lib.Service;
// Heading of the application
heading_txt.text = "Modifying landmarks";
// Define Arrays for information of landmarks
var idList:Array = new Array();
var landmarkList:Array = new Array();
var longitudeList:Array = new Array();
var latitudeList:Array = new Array();
var i = 0;
// Create new Service object which has Landmark information
var landmark = new Service("Service.Landmarks", "IDataSource");
// Get list of the landmarks
listLandmarks();
// Define number of the last item
var lastItem = idList.length-1;
// Trace information of the landmark to the inputs
setTexts();
/**********************************************************
** Function for setting the texts to inputs
**********************************************************/
function setTexts() {
nro_txt.text = i+1+"/"+idList.length;
if(landmarkList[i] == undefined) {
landmark_txt.text = "";
} else {
landmark_txt.text = landmarkList[i];
};
if(longitudeList[i] == undefined) {
longitude_txt.text = "";
} else {
longitude_txt.text = longitudeList[i];
};
if(latitudeList[i] == undefined) {
latitude_txt.text = "";
} else {
latitude_txt.text = latitudeList[i];
};
};
/**********************************************************
** Function for getting updated list of the landmarks
**********************************************************/
function listLandmarks() {
// Define input parameters
var inParams = {Type:"Landmark"};
// Define result value
var outParams = landmark.GetList(inParams);
// Check if getting the list success
if (outParams.ErrorCode == 0) {
outList = outParams.ReturnValue;
outputEntry = null;
// Format arrays
idList = [];
landmarkList = [];
longitudeList = [];
latitudeList = [];
do {
outputEntry = outList.next();
if (null != outputEntry) {
// Get the lists of IDs and landmark information to Arrays
idList.push(outputEntry.id);
landmarkList.push(outputEntry.LandmarkName);
longitudeList.push(outputEntry.LandmarkPosition.Longitude);
latitudeList.push(outputEntry.LandmarkPosition.Latitude);
} else {
break;
}
} while (true);
} else {
// if errors trace them to the textfield
errorId = outParams.ErrorCode;
error_txt.text = "Error while listing: "+errorId+"\r";
}
}
/**********************************************************
** Function for pressing the Edit button.
** Calls Add() method synchronously.
** Edit name and position information of the shown landmark.
**********************************************************/
edit_mc.onPress = function() {
// Get ID from the array
var landmarkId = idList[i];
// Get other information 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 = {
id:landmarkId, 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) {
error_txt.text = landmarkName+" edited";
}
else {
errorId = outParams.ErrorCode;
error_txt.text = "Error while editing: "+errorId;
};
listLandmarks();
};
/**********************************************************
** Function for pressing the Stop button.
** Calls Delete() method synchronously.
** Method deletes the landmark
**********************************************************/
delete_mc.onPress = function() {
var landmarkDeleteId = {id:idList[i]};
var inParams = {Type:"Landmark", Data:landmarkDeleteId};
var outParams = landmark.Delete(inParams);
if (outParams.ErrorCode == 0) {
error_txt.text = landmarkList[i]+" deleted";
}
else {
errorId = outParams.ErrorCode;
error_txt.text = "Error while deleting: "+errorId;
};
listLandmarks();
i = 0;
lastItem = idList.length-1;
setTexts();
};
/**********************************************************
** Function for pressing the Prev button
**********************************************************/
prev_mc.onPress = function() {
if(i == 0) {
i = lastItem;
} else {
i--;
};
setTexts();
error_txt.text = "";
};
/**********************************************************
** Function for pressing the Next button
**********************************************************/
next_mc.onPress = function() {
if(i == lastItem) {
i = 0;
} else {
i++;
};
setTexts();
error_txt.text = "";
};
/**********************************************************
** Function for pressing the Exit button.
**********************************************************/
exit_mc.onPress = function() {
status = fscommand2("Quit");
trace("QUIT");
};
Postconditions
Landmark name, longitude, and latitude information of the device are displayed as inputs. You can edit a landmark by editing input and pressing the Edit button. If there is more than one landmark you can browse them by pressing the Prev and Next buttons. A landmark can be deleted by pressing the Delete button.
Example application
The following sample application has been tested in the Nokia 5800 XpressMusic (S60 5th Edition, Flash Lite 3.0). File:FlashLite Modifying Landmarks.zip
See also
- Flash Lite API reference in the Flash Lite Developer's Library
- Adding a landmark in Flash Lite
- Importing landmarks in Flash Lite
- Exporting landmarks in Flash Lite

