help on accessing inbuilt gps of mobile device
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
Re: help on accessing inbuilt gps of mobile device
ok just to make it absolutely clear : NO, you wont be able to get your actual location through the emulator... Keep in mind it's an emulator, GPS is a combination of hardware and software, and what you are missing is actually the hardware (GPS chipset and for example an inbuilt antenna to receive the GPS signals)....
So what the emulator can do for you is actually "simulate" or "spoof" a location, which is supplied by you or might be generated randomly, so this position is NOT your actual position !!!
You will need real actual hardware (a device with inbuilt gps or an external gps-mouse) to actually read out your actual position...
To me it sounds you might want to learn a little more about a software emulator in general (again an emulator is not an actual device, for example you cannot use the camera just as you cannot use the internal GPS) and how GPS (chipsets) work....
Also you might want to have a look at this discussion :
[url]http://www.developer.nokia.com/Community/Discussion/showthread.php?238935-For-testing-GPS-based-J2ME-app-Is-there-any-emulator-which-have-in-build-GPS[/url]
Re: help on accessing inbuilt gps of mobile device
so every time i want to test my app have to install that app in mobile having inbuilt gps ... i have Nokia E52 which has inbuilt GPS but in that it is only asking for my bluetooth connection and awaiting for the signal and finally cannot find any signal .... is there any mistakes or some missing part in my code so that i can cross check whether my code is right or wrong .. i am stuck here since a month plzz help..
thankss
swati
Re: help on accessing inbuilt gps of mobile device
[QUOTE=swatik;909759]so every time i want to test my app have to install that app in mobile having inbuilt gps ... i have Nokia E52 which has inbuilt GPS but in that it is only asking for my bluetooth connection and awaiting for the signal and finally cannot find any signal .... is there any mistakes or some missing part in my code so that i can cross check whether my code is right or wrong .. i am stuck here since a month plzz help..
thankss
swati[/QUOTE]
Check the device settings is the inbuilt GPS/ A-GPS is off or disabled - On/enable it before testing this app.
Also test running apps like Google Maps or Nokia Maps or any default device location app and test in open sky to see if your gets a GPS lock first... if it works then test your J2me app it should also get the GPS location.
Re: help on accessing inbuilt gps of mobile device
Have a look at :
[url]http://www.developer.nokia.com/Community/Wiki/Obtaining_GPS_fix_using_Java_ME[/url]
Also there are other handy articles on the Wiki regarding Location and JSR 179
Re: help on accessing inbuilt gps of mobile device
[QUOTE=swatik;909759]so every time i want to test my app have to install that app in mobile having inbuilt gps ...
i am stuck here since a month plzz help..[/QUOTE]Why would you need the emulator to provide your real coordinates (which it can not do anyway)? It is a good thing actually that you can set the emulator to think itself being anywhere on the planet.
Re: help on accessing inbuilt gps of mobile device
Just to add : I hope you have seen Route Editor in Nokia SDK 2.0 for Java / Series 40 SDK's - Would Route Editor help in your case ?
Regards
Gopal