1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| public void run()
{
/**
* Entry point of the thread
*
* EFFECTS: call to connect() method
*/
while (true) {
try {
checkLocation();
} catch (Exception ex)
{
ex.printStackTrace();
//midlet.displayString(ex.toString());
System.out.println("1->" + ex.toString());
}
if (isActive == false)
break;
}
}
public void checkLocation() throws Exception
{
// horizontal accuracy in meters
int HORIZONTAL_ACCURACY = 500;
// timeout when the current location is requested
int REQUEST_TIMEOUT = 60;
String string;
Location l;
LocationProvider lp;
Coordinates c;
// Set criteria for selecting a location provider:
// accurate to 500 meters horizontally
Criteria cr = new Criteria();
cr.setHorizontalAccuracy(HORIZONTAL_ACCURACY);
// get an instance of the provider
lp = LocationProvider.getInstance(cr);
// Request the location, setting a one-minute timeout
l = lp.getLocation(REQUEST_TIMEOUT);
c = l.getQualifiedCoordinates();
if (c != null ) {
// Use coordinate information
latitude = c.getLatitude();
longitude = c.getLongitude();
string = "\nLatitude : " + Utils.formatDouble(latitude, 3) + "\nLongitude : " + Utils.formatDouble(longitude, 3);
isAvailable = true;
} else {
string ="Location API failed";
isAvailable = false;
}
//midlet.displayString(string);
System.out.println("2->" + string);
update_counter++;
splashScreenUI.repaint();
} |
Partager