how do i access inbuilt gps of mobile device or emulator in java, for my project i want to get my current location automatically as i have the code for it
String string;
LocationProvider lp ;
Coordinates c;
// Set criteria for selecting a location provider:
// accurate to 500 meters horizontally
Criteria cr= new Criteria();
public void startApp()
{
try {
ApplicationContext.getInstance().setToken("rNfKF7rkL6ERcji5fXFDWg");
ApplicationContext.getInstance().setAppID("xMFc0ozI03u-KzEQ--MG");
cr.setHorizontalAccuracy(1000);
cr.setVerticalAccuracy(1000);
cr.setPreferredPowerConsumption(Criteria.POWER_USAGE_HIGH);
LocationProvider lp= LocationProvider.getInstance(cr);
Location loc = lp.getLocation(-1);
QualifiedCoordinates qc =loc.getQualifiedCoordinates();
Display display = Display.getDisplay(this);
MapDemo minimalMap = new MapDemo(display, this);
minimalMap.getMapDisplay().setCenter(new GeoCoordinate(qc.getLatitude(),qc.getLongitude(),qc.getAltitude()));
minimalMap.getMapDisplay().setZoomLevel(14,0,0);
display.setCurrent(minimalMap);

} catch (LocationException ex) {
ex.printStackTrace();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}

protected void pauseApp()
{
throw new UnsupportedOperationException("Not supported yet.");
}

protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
throw new UnsupportedOperationException("Not supported yet.");
}

}
class MapDemo extends Base {
public MapDemo(Display display, MIDlet midlet) {
super(display, midlet);
}
}

class Base extends MapCanvas implements CommandListener {

private final Command EXIT = new Command("Exit", Command.EXIT, 1);
protected MIDlet midlet; // for notifyDestroyed

public Base(Display display, MIDlet midlet) {
super(display);
this.midlet = midlet;
addCommand(EXIT);
setCommandListener(this);
}

public void commandAction(final Command c, Displayable d) {
Command YES = new Command("YES", Command.OK, 1);
Command NO = new Command("NO", Command.OK, 1);
if (c == EXIT)
{
midlet.notifyDestroyed();
}
else if (c == YES)
{
map.reconnect();
display.setCurrent(this);
}
else if (c == NO)
{
display.setCurrent(this);
}
else
{

commandRun(c);

}
}

private void commandRun(Command c) {

}

public void onMapUpdateError(String string, Throwable thrwbl, boolean bln)
{

}

public void onMapContentComplete()
{
throw new UnsupportedOperationException("Not supported yet.");
}
}


this code is not displaying my current location, and it is Showing me dynamic coordinates every time i run .... but if i give coordinates of particular location manually in GeoCoordinate method it is showing me the exact location but the thing is i want it to read automatically my current location...and display it on my map
can anyone plzz help me about where i am going wrong or first should i need some code to first connect to inbuilt gps of mobile device
IF YES THEN
what is the idea behind connecting inbuilt GPS of mobile device or emulator
IF NO
how i will get my current location coordinates
plzz help

thankss
swati