dear experts,
l'm trying to write a simple midlet that read the location information from nokia 6110 Navigator inbuild GPS, the code as below and the midlet responsed "Location request time out". l'm using pretty sure that the phone supports Location API as mentioned in this link
http://www.forum.nokia.com/devices/6110_Navigator, anything wrong in my code? appreciate any helps. many thanks.
import javax.microedition.midlet.
*;
import javax.microedition.lcdui.*
;
import javax.microedition.locatio
n.*;
import java.util.Date;
public class TestLocation extends MIDlet implements LocationListener{
private Display display;
private Form form;
private LocationProvider locationProvider = null;
private Coordinates oldCoordinates = null, currentCoordinates = null;
private float distance = 0;
private int azimuth = 0;
public TestLocation(){
}
public void startApp() {
display = Display.getDisplay(this);
if (form == null) {
form = new Form("TestLocation");
display.setCurrent(form);
}
try {
// Create a Criteria object for defining desired selection criteria
Criteria cr = new Criteria();
LocationProvider lp = LocationProvider.getInstan
ce(cr);
// get the location, one minute timeout
Location l = lp.getLocation(60);
Coordinates c = l.getQualifiedCoordinates(
);
if (c != null) {
// use coordinate information
displayMessage(String.valu
eOf(c.getL
atitude())
);
}else{displayMessage("Noth
ing");
}
} catch (Exception e) {
displayMessage(e.getMessag
e());
// not able to retrive location information
}
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {
}
public void displayMessage(String s) {
Alert a = new Alert("", s, null, null);
a.setTimeout(Alert.FOREVER
);
display.setCurrent(a, form);
}
public void locationUpdated(LocationPr
ovider provider, final Location location) {
}
// one of the required methods of the LocationListener interface, not used by us
public void providerStateChanged(Locat
ionProvide
r provider, int newState) {
}
}
regards
eddie
Start Free Trial