Back | Tutorial Home | Next
Landmarks provide power of Persistence of location data for location aware applications. The Position information can be stored in this data store and can be used by the application at a later stage. The container for this datastore is called Landmark Store. You can also categorize the landmarks stored in this Landmark Store.
Suppose you want to create a city guide. Your design for this datastore will have the following structure.
Landmark Store: Lets
call our Landmark Store as CityGuide
Categories: CityGuide can be segregated into various categories like
Cinemas, Restaurants, Railway Stations, Shopping Malls, and Markets etc.
Landmarks: Each of these categories will contain specific Items, like
restaurants can contain all the restaurants in that city.
AddressInfo: Textual address information about a location like street,
postal code, city, etc.
Other MIDlets can also access your Landmark Store. There is no security restriction to Landmark Stores like in RMS.
The architecture of Landmark Store is given in the below figure.
Programming Landmark Stores
Location API provides class LandmarkStore for storing Landmarks. to create a new Landmark store use createLandmarkStore().
LandmarkStore.createLandmarkStore("MyLandmarkDB");
|
WhereWasILandmarks is the name of the landmark store.
To get handle to the existing landmark store use getInstance() method.
LandmarkStore myLandmarkStore = LandmarkStore.getInstance("MyLandmarkDB");
|
Now that you have the handle to the LandmarkStore you can sub-devide it into categories. To create categories use addCategory() method.
myLandmarkStore.addCategory("Restaurants");
myLandmarkStore.addCategory("Railway Stations");
myLandmarkStore.addCategory("Grociries");
myLandmarkStore.addCategory("Subways");
|
To create the Landmarks use Landmark class. To create a new landmark use constructor
Landmark(String name, String description, QualifiedCoordinates coordinates, AddressInfo addressInfo) |
Parameters
name: name of the
created landmark.
description: description associated with the created Landmark.
QualifiedCoordinates: Coordinates with accuracy.
AddressInfo: Textual address information about a location like street,
postal code, city, etc.
Example:
Landmark landmark = new Landmark("Salsa Restaurant”,
” Spicy recipes and Tangy dances",
new QualifiedCoordinates(14.389796708964603, 50.09985002736201,310, 41.222, 30.000) ,
textAddress);
|
Now you have LandmarkStore with a Category and a Landmark. Finally you should insert this Landmark into Landmark Store at a specific category..
myLandmarkStore.addLandmark(landmark, "Restaurants"); |
AddressInfo
This class contains textual address information about a location. This is a
part of the Landmark and it is a vendors responsibility to localize it.
AddressInfo Has following fields
These fields can be accessed by using
getField(int field)
: To get the value of the field.
setField(int field, value): To set a value to the field.
Examples
To create AddressInfo
AddressInfo textAddress = new AddressInfo(); textAddress.setField(AddressInfo.COUNTRY , "UK"); textAddress.setField(AddressInfo.CITY , "London"); Landmark landmark = new Landmark(name,description, new QualifiedCoordinates(latitude, longitude, altitude, hAccuracy, vAccuracy) ,textAddress); |
To retrieve AddressInfo
String country = landmark.getAddressInfo().getField(AddressInfo.COUNTRY); String city = landmark.getAddressInfo().getField(AddressInfo.CITY); |
Landmark Store MIDlet "Where Was I?"
In the example "Where Was I?" a trail is created of the locations passed by the user. The user can store a landmark of his location in the LandmarkStore 'myTrailStore" with a name and location. All these landmarks are stored in the category "LostInLondon".
Code segment for Creation of Landmark Store and Catogories is in the class WhereWasI.java
// Check if the Landmark Store already exists
String allStores[] = LandmarkStore.listLandmarkStores();
boolean doesStoreExist=false;
for(int i=0; i<allStores.length; i++) {
if(allStores[i].equals("WhereWasILandmarks")) {
doesStoreExist = true;
}
}
// Create a new Lanmark Store if the store does not exist
if(!doesStoreExist){
LandmarkStore.createLandmarkStore("WhereWasILandmarks");
}
myTrailStore = LandmarkStore.getInstance("WhereWasILandmarks");
// Add category
myTrailStore.addCategory("LostInLondon");
|
Code segment to add Landmarks to Landmark Store is in the Thread class LandmarkPosition.java
Criteria cr = new Criteria(); // Required Accuracy is set to 100 Meters cr.setHorizontalAccuracy(100); LocationProvider provider = LocationProvider.getInstance(cr); // 90 secs is the time out Location location = provider.getLocation(90); QualifiedCoordinates c = location.getQualifiedCoordinates(); double latitude = c.getLatitude(); double longitude = c.getLongitude(); float altitude = c.getAltitude(); float hAccuracy = c.getHorizontalAccuracy(); float vAccuracy = c.getVerticalAccuracy(); // Same Address Info for all landmarks. AddressInfo textAddress = new AddressInfo(); textAddress.setField(AddressInfo.COUNTRY , "UK"); textAddress.setField(AddressInfo.CITY , "London"); Landmark landmark = new Landmark(name,description,new QualifiedCoordinates (latitude, longitude, altitude, hAccuracy, vAccuracy) ,textAddress); Landmark landmark = new Landmark(name,description,new QualifiedCoordinates (latitude, longitude, altitude, hAccuracy, vAccuracy) ,null); myTrailStore.addLandmark(landmark, "LostInLondon"); |
Code segment to display Landmarks in the Landmark Store is in the class WhereWasI.java
String landmarksStr = "\nClick 'Add' to add your present location.
\nYour Previous Landmarks: \n";
try {
Enumeration landmarkEnum = myTrailStore.getLandmarks();
int count=0;
while (landmarkEnum.hasMoreElements()) {
count = count + 1;
Landmark landmark = (Landmark)landmarkEnum.nextElement();
double latitude = landmark.getQualifiedCoordinates().getLatitude();
double longitude = landmark.getQualifiedCoordinates().getLatitude();
String landmarkName = landmark.getName();
String country = landmark.getAddressInfo().getField(AddressInfo.COUNTRY);
landmarksStr = landmarksStr + landmarkName + " >>Lat: " + latitude + ",Long: "
+ longitude + ",Country: " +country + "\n"; }
}catch(Exception e){
landmarksStr = landmarksStr + "There are no Landmarks in your 'Where Was I' Store\n";
}
|
Download the complete application from salsa goodies.
Managing Landmark Stores in KToolbar
KToolbar provides you GUI utility to manage your Landmarks. Here you can manage your Landmark Stores, Categories and Landmarks and Address Info.
In your KToolbar window go to File>Utilities>Manage Landmarks to get the screen shown below
| j2meSasa goodies | |
| Download demo code for deploying directly to WTK | Click here to download Zip File Containing WTK compatible file structure. This zip file is a MIDlet suite of all the examples in this in this LBS tutorial |
Back
| Tutorial Home | Next
More Tutorials
This page is a part of
a frames based web site. If you have landed on this page from a search engine
click here to view the complete page.