I am working on a j2me application which contain a class to find the location of mobile using GPS.I need to include gauge while the location provider API is called and it finds the location.I am new to j2me so still not clear with all the concepts.I am pasting my code below.Please help me through this.Thanks in advance..
package org.ets.utils;
import javax.microedition.lcdui.*;
import javax.microedition.location.*;
import javax.microedition.io.*;
import java.io.*;
import org.ets.midlet.ETS_infozech;
import javax.microedition.midlet.*;
public class Locfinder {
public Locfinder(ETS_infozech midlet)
{
this.midlet = midlet;
}
public static String ex()
{
try {
checkLocation();
} catch (Exception ex)
{
ex.printStackTrace();
}
//System.out.println(string);
return string;
}
public static void checkLocation() throws Exception
{
Location l;
LocationProvider lp;
Coordinates c;
// Set criteria for selecting a location provider:
// accurate to 500 meters horizontally
Criteria cr= new Criteria();
cr.setHorizontalAccuracy(500);
// Get an instance of the provider
lp= LocationProvider.getInstance(cr);
//Request the location, setting a one-minute timeout
l = lp.getLocation(60);
c = l.getQualifiedCoordinates();
if(c != null ) {
// Use coordinate information
double lat = c.getLatitude();
double lon = c.getLongitude();
string = " LAT-" + lat + " LONG-" + lon;
}
}
}
There's no way you can link a
Gaugeto some task.You have to set values to the
Gaugemanually. So you'd create aGaugeand add it to yourForm. Then start your code to perform the look-up.In between your lines of code, you'd add
myGauge.setValue(some_value);to increase the indicator.Of course, this becomes difficult when most of the task is contained in a single line of code, like e.g.
lp.getLocation(60);. I think, in that case, I would create aThreadthat automatically increases the value on theGaugein the 60 seconds, but can be stopped/overridden by a manual setting.You would then create a
Gaugeand add it to yourFormThen start the auto-increment.
And then call your look-up code.
Inside your look-up code, add code to stop the auto-incrementing and set the
Gaugeobject to 100%, if the look-up was successful (meaning before the timeout).