hi sir,
i've tested fined the GPS in nokia 6110 Navigator with some shareware of MIDlet that read Position Informations from build-in GPS. now i'm trying to write a simple MIDlet that performs the same, the code as below and the midlet responsed "Location request timed out". seems like unable to read the information from GPS device, did i missed anything in the code? appreciate any helps. many thanks.
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.location.*;
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.getInstance(cr);
// get the location, one minute timeout
Location l = lp.getLocation(60);
Coordinates c = l.getQualifiedCoordinates();
if (c != null) {
// use coordinate information
displayMessage(String.valueOf(c.getLatitude()));
}else{displayMessage("Nothing");
}
} catch (Exception e) {
displayMessage(e.getMessage());
// 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(LocationProvider provider, final Location location) {
}
public void providerStateChanged(LocationProvider provider, int newState) {
}
}
regards
eddie

Reply With Quote

