I wrote a very simple application that asks the LocationProvider for a location and prints it to System.out. This works great in the simulator. However, when I run it on my blackberry device, the call to getLocation seems to hang indefinitely. I am running the code in a separate thread that simply gets a provider and asks for the location. I tried it with null Criteria (which should give me the defaults right?) as well as a Criteria that should provide Assist then Autonomous. I've included my code below. When I run this on my device it hangs on the call to getLocation.Here is my code below..plzz tell what i might be doing wrong...
public void getLocation() {
Thread t = new Thread(new Runnable() {
private double lat;
private double lon;
public void run() {
Criteria cr = new Criteria();
cr.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);
cr.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
cr.setCostAllowed(false);
cr.setPreferredPowerConsumption(Criteria.NO_REQUIREMENT);
cr.setPreferredResponseTime(1000);
LocationProvider lp = null;
try {
lp = LocationProvider.getInstance(cr);
} catch (LocationException e) {
// System.out.println("*****************Exception" + e);
}
Coordinates c = null;
if (lp == null) {
UiApplication.getUiApplication().invokeLater(
new Runnable() {
public void run() {
Dialog.alert("GPS not supported!");
return;
}
});
} else {
// System.out.println("OK");
switch (lp.getState()) {
case LocationProvider.AVAILABLE:
// System.out.println("Provider is AVAILABLE");
Location l = null;
try {
l = lp.getLocation(-1);
} catch (LocationException e) {
// System.out.println("***Location Exception caught "
// + e);
} catch (InterruptedException e) {
// System.out.println("***Interrupted Exception aught:"
// + e);
} catch (Exception e) {
// System.out.println("***Exception caught :"
// ;+ e);
}
if (l != null && l.isValid()) {
c = l.getQualifiedCoordinates();
}
if (c != null) {
lat = c.getLatitude();
lon = c.getLongitude();
System.out.println(lat + " - " + lon);
}
}
}
}
});
t.start();
}