public class MyGPSTraker extends MIDlet implements CommandListener {
//Application Interface
private Form form = null;
private StringItem textItem = null;
private Command exitCommand = null;
private boolean bStarted = false;
private boolean bStop = false;
//Bluetoth Objects
//ATTENTION: The following constant has to be set with the address
//of your Bluetooth GPS Receiver device.
private final String deviceURL = „btspp://00157F018A2B:1;authenticate=false;encrypt=false;master=false”;
private BluetoothGPS bluetoothGps = null;
//----MIDlet---------------------------------------------------------
public MyGPSTraker(){
textItem = new StringItem(””,”Starting...”);
exitCommand = new Command(”Exit”, Command.EXIT, 1); // exit the application
form = new Form(”nicusoare’s GPS Traker”);
form.append(textItem);
form.addCommand(exitCommand);
form.setCommandListener(this);
}
protected void startApp() {
if (!bStarted) {
bStarted = true;
Display.getDisplay(this).setCurrent(form);
DoGPSTrack();
}
}
protected void pauseApp() {}
protected void destroyApp(boolean force) {}
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
bStop = true;
destroyApp(false);
notifyDestroyed();
}
}
//----Bluetooth Methods-----------------------------------------------
private void DoGPSTrack() {
bluetoothGps = new BluetoothGPS(deviceURL);
boolean connection_existed=false;
//Current Read
int ioldTextToScreen = 0;
boolean bValidRead = false; //Valid GPS Device Reading
boolean bValidSignal = false;//Valid GPS Fix Position
while (!bStop) {
try{
bValidRead = false; //Valid GPS Device Reading
bValidSignal = false;//Valid GPS Fix Position
//Read Device and Validate Data
bValidRead = bluetoothGps.ReadGps ();
if (bValidRead) {
bValidSignal = bluetoothGps.FixStatus;
connection_existed=true;
if(bValidSignal){//Validate GPS Fix
DisplayPozition();
} else {
DisplayWaiting();
}
} else {
if(connection_existed) {
textItem.setText(”Disconnected!”);}
else {
textItem.setText(”Not Connected!”);
}
bluetoothGps.Close();
}
}catch(Exception e){//General Error Unknown
textItem.setText(”Error: „+e.getMessage());
}
}
bluetoothGps.Close();
}