Using Landmarkstore class to retrieve landmarks and find out distance to landmark in Java ME

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): S60 5th Edition SDK emulator and devices
Platform(s): S60 5th Edition
S60 5th Edition
Keywords: Location API (JSR-179), javax.microedition.location, javax.microedition.location.LandmarkStore
Created: User:Kbwiki (28 Jun 2010)
Last edited: hamishwillee (26 Jun 2013)


The LandmarkStore class provides methods to store, delete, and retrieve landmarks from a persistent landmark store. There is one default landmark store and there may be multiple other named landmark stores.

The landmarks have a name and may be placed in a category or several categories. The category is intended to group landmarks that are of similar type to the end user.

Source file

Header files

import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.location.*;
import java.util.Enumeration;


 public class Landmark extends MIDlet implements CommandListener {
 private Display display;
 private Form mainForm;
 private Alert positionAlert;
 private LandmarkStore landmarkStore;
 private ChoiceGroup landmarkList;
 public void startApp() {
 mainForm = new Form("Landmark");
 StringItem Msg = new StringItem("welcome", "Press OK to see list of
 mainForm.addCommand(new Command("Exit", Command.EXIT, 0));
 mainForm.addCommand(new Command("OK", Command.OK, 1));
 display = Display.getDisplay(this);

 private void build(){
  //To create a new Landmark store use createLandmarkStore().
  //To get handle to the existing landmark store use getInstance() method.
    landmarkStore = LandmarkStore.getInstance("Landmarks");
  //This returns the handle to the default store available.
  //landmarkStore = LandmarkStore.getInstance(null);
  //You can sub-divide LandmarkStore it into categories
    landmarkStore.addCategory("Railway Stations");
  //To create AddressInfo
    AddressInfo textAddress = new AddressInfo();
    textAddress.setField(AddressInfo.COUNTRY , "UK");
    textAddress.setField(AddressInfo.CITY , "London");
  //To create the Landmarks use Landmark class. To create a new landmark use
  // constructor
    Landmark landmark = new Landmark("Appolo","Cardio centre",new
    QualifiedCoordinates(40.689, 74.045, 0, Float.NaN, Float.NaN),textAddress);
  //Insert this Landmark into Landmark Store at a specific category.
    landmarkStore.addLandmark(landmark, "Hospitals");

To retrieve information

    //using the instance of landmarkstore created earlier
      Enumeration landmarkEnum =
      Landmark landmark = (Landmark)landmarkEnum.nextElement();
   //Get coordinates of the target landmark
      Coordinates target = landmark.getQualifiedCoordinates();
      Criteria cr = new Criteria();

   //Represents a source of location information
      LocationProvider lp = LocationProvider.getInstance(cr);
      Location l = lp.getLocation(60);    
   //Get coordinates of present location
     Coordinates present = l.getQualifiedCoordinates();
   //To get the distance between present and target location
       if ( target!= null)
            float distance = target.distance(present);
   //To get other parameters
      double latitude = target.getLatitude();
      double longitude = target.getLongitude();
   //To get the name of the landmark
      String landmarkName = landmark.getName();
   //To retrieve the AddressInfo
      String country = landmark.getAddressInfo().getField(AddressInfo.COUNTRY);
      String city = landmark.getAddressInfo().getField(AddressInfo.CITY);
   //To retrieve the landmarkstore available in other drives as well
      String[] storeNames = LandmarkStore.listLandmarkStores();
        if (storeNames != null) 
             for (int j = 0; j < storeNames.length; j++) 

Sample application


This page was last modified on 26 June 2013, at 08:42.
45 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.