LocationManager lm = LocationManager.getLocationManager();
InfiniteProgress inf = new InfiniteProgress();
final Dialog progress = inf.showInifiniteBlocking();
MyLocationListener m = new MyLocationListener();
lm.setLocationListener(m);
try{
System.out.println("Current location: " + lm.getCurrentLocation());// This code does not change anything.
} catch (Exception e){}
Display.getInstance().invokeAndBlock(m);
System.out.println("Baigta");
progress.dispose();
showMeOnMap();
lm.setLocationListener(null);
int status = lm.getStatus();
LocationListener source code. From other similar thread:
class MyLocationListener implements LocationListener, Runnable {
boolean locationReady;
int status;
public void locationUpdated(Location loc) {
locationReady = true;
}
public void providerStateChanged(int newState) {
// check for unavailable errors etc.
status = newState;
locationReady = true;
}
public void run() {
// I recommend adding a timeout and setting the status to an error value for timeout
while (!locationReady) {
// sleep is find here because this isn't the EDT
try {
System.out.println("Sleeping");
Thread.sleep(100);
} catch (InterruptedException err) {
}
}
}
}