LandmarkManager.java
/**
* Copyright (c) 2012 Nokia Corporation. All rights reserved.
* Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
* Oracle and Java are trademarks or registered trademarks of Oracle and/or its
* affiliates. Other product and company names mentioned herein may be trademarks
* or trade names of their respective owners.
* See LICENSE.TXT for license information.
*/
package com.nokia.example.compass;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;
import javax.microedition.location.Landmark;
import javax.microedition.location.LandmarkStore;
import javax.microedition.location.QualifiedCoordinates;
// A convenience class for dealing with the landmark API.
public class LandmarkManager
{
private LandmarkStore store;
public LandmarkManager()
{
// Get the default landmark store (with no name specified)
store = LandmarkStore.getInstance(null);
}
private void addExampleLandmarksToVector(Vector to) {
Landmark mecca = new Landmark("Mecca", null, new QualifiedCoordinates(21.416667, 39.816667, Float.NaN, Float.NaN, Float.NaN), null);
Landmark EiffelTower = new Landmark("Eiffel Tower", null, new QualifiedCoordinates(48.8583, 2.2945, Float.NaN, Float.NaN, Float.NaN), null);
Landmark StatueOfLiberty = new Landmark("Statue of liberty", null, new QualifiedCoordinates(40.689167, -74.044444, Float.NaN, Float.NaN, Float.NaN), null);
to.addElement(mecca);
to.addElement(EiffelTower);
to.addElement(StatueOfLiberty);
}
public Vector getLandmarks()
{
Vector landmarks = new Vector();
if (null == store)
return landmarks;
try
{
Enumeration e = store.getLandmarks();
while (e.hasMoreElements())
{
Landmark landmark = (Landmark) e.nextElement();
landmarks.addElement(landmark);
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
addExampleLandmarksToVector(landmarks);
return landmarks;
}
public boolean saveLandmark(String name, QualifiedCoordinates coordinates) {
boolean ret = false;
Landmark landmark = new Landmark(name, null, coordinates, null);
try {
store.addLandmark(landmark, null);
ret = true;
}catch(IOException io) {
System.out.println("Save landmark:" + io.getMessage());
}
return ret;
}
}