I wrote a very simple application that queries LocationProvider for a location and prints it to System.out. This works great in a simulator. However, when I run it on my Blackberry device, the getLocation call seems to hang indefinitely. I run the code in a separate thread that just gets the provider and requests it. I tried this with null criteria (which should give me default permissions?), As well as the criteria that Assist should provide, and then Standalone. I have included my code below. When I run this on my device, it hangs when calling getLocation.Here my code is below .. plzz says that I can do it 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) {
}
Coordinates c = null;
if (lp == null) {
UiApplication.getUiApplication().invokeLater(
new Runnable() {
public void run() {
Dialog.alert("GPS not supported!");
return;
}
});
} else {
switch (lp.getState()) {
case LocationProvider.AVAILABLE:
Location l = null;
try {
l = lp.getLocation(-1);
} catch (LocationException e) {
} catch (InterruptedException e) {
} catch (Exception 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();
}