×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Feb 2006
    Posts
    150

    Refreshing coordinates with JSR-179!

    Hi, people!

    I'm having problemas with the use JSR-179 API!

    I would like to know how to refresh the coordinates of my GPS BT device because I always paint the same GPS data when I call the coordinates=location.getQualifiedCoordinates()
    method.

    Do you know if I need to refresh my "Location" instance with the line:
    location= localProvider.getLocation(timeout) ?

    I include a snippet of code to understand easily my problem:

    LocationProvider lp= LocationProvider.getInstance(null);
    if (lp!=null){

    Location l= lp.getLocation(-1);

    //Retrieve the GPS data continuously!
    Coordinates c;
    double lat, lon;
    float alt,speed;
    long timestamp;

    while(trucking) {
    //Retrieve the coordinate information
    c=l.getQualifiedCoordinates();
    if (c!=null){

    //Use coordinate information
    lat = c.getLatitude();
    lon = c.getLongitude();
    alt = c.getAltitude();
    speed=l.getSpeed();
    timestamp=l.getTimestamp();
    }else{
    //No valid data are available!
    lat=0;
    lon=0;
    alt=0;
    speed=-1;
    timestamp=0;
    }

    //Paint coordinate information

    }
    Thanks in advance!

  2. #2
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: Refreshing coordinates with JSR-179!

    hi,

    I'm using listener, that simple and effective solution - note that my GPS lw-d3 nokia module data varies at time (I think that depends on satelites data available, etc) - so using listener seems effective for me and works quite stable on 3250+GSP module,
    So I'm not using any thread technically speaking, data is provided asynchronously into application module that handles coords and renders ui,
    Code:
    void createLocationProvider() {
            if (locationProvider == null ) {
                try {
                    locationProvider = LocationProvider.getInstance(null);
                    if(locationProvider == null){
                        debug("cannot create provider");
                    } else {
                        locationProvider.setLocationListener(this, -1, -1, -1);
                      ...........................
                    }
                } catch (LocationException le) {
                    debug("Cannot create LocationProvider for this criteria.");
                    debug(le.getMessage());
                }
            }
        }
    also I would simply try to call getLastKnownLocation() from provider instead of querying for coords contantly, just a though - i'm not yet exeperienced with LBS

    regards,
    Peter

  3. #3
    Regular Contributor
    Join Date
    Feb 2006
    Posts
    150

    Talking Re: Refreshing coordinates with JSR-179!

    Thanks Peter for being always here to help new Nokia developers in their problems!

    Several minutes after writing this post, I thought of refreshing the "Location" object inside the loop (with this code line lp.getLocation(-1)) and I tested the new MIDlet with the Sun Java Wireless Toolkit 2.3 Beta and it worked perfectly with a simulation of movement! The Cartesian coordinates were being refreshed continuously!

    I haven't tested it yet with the real devices (my Nokia phone and my Leadtek GPS)... so, now with your answer I asked myself:

    What is better, to refresh this "Location" object or to use a "LocationListener" object?

    I'm testing these two options and if I have some interesting conclusions we can talk about them!


    Thanks!
    Last edited by Summerman; 2006-10-15 at 19:45.

  4. #4
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: Refreshing coordinates with JSR-179!

    hi,

    it could be probably design choice, application I've installed uses interval for refreshing location data, my one is using listener,

    docs simply mentions that its up to implementation to provide best update interval for listener:
    http://www.forum.nokia.com/ME_Develo...nListener.html
    or even delay it:
    http://www.forum.nokia.com/ME_Develo...BBBBB4259.html

    regards,
    Peter

  5. #5
    Regular Contributor
    Join Date
    Feb 2006
    Posts
    150

    Arrow Re: Refreshing coordinates with JSR-179!

    Thanks Peter, people missed you in this forum!

    I've tested the two possibilities and one of them works an the other doesn't work! My way of refreshing data works but it has the disadvantage of asking for the user permission continuously, if you didn't set the "Location permission" to "Ask only the 1st time".

    On the other hand, I've written the necessary code to use your way of refreshing the data but it is like the N93 is frozen! I want to tell you that I prefer your way of doing that because you can act in consequence when the listener calls you and informs you about a GPS state changed, for example.

    I write you a snippet of my code and if you note that something is wrong, please tell me! I have to tell you that these two different ways work perfectly in the Java Sun Wireless Toolkit 2.3Beta! I can't understand why it doesn't work in the real device N93!

    Code:

    //----------------------------------------------------------------------------------------------------------//

    private LocationProvider createLocationProvider(Criteria cr){
    LocationProvider lp=null;
    try {
    if (((lp=LocationProvider.getInstance(cr))!=null) ||
    ((lp = LocationProvider.getInstance(null))!=null)){//Set the least restrictive Criteria!
    lp.setLocationListener(this, -1, -1, -1);//LocationListener,interval,timeout,maxAge//LocationListener is in this class!
    }else if(lp==null){

    d.setCurrent(newAdvisor("LocationException","\nCannot create a LocationProvider!",5000),gpsGui);
    }
    } catch (LocationException le) {
    d.setCurrent(new Advisor("LocationException","\nCannot create a LocationProvider for this Criteria!",5000),gpsGui);
    } catch (Exception e){/////////////////////
    d.setCurrent(new Advisor("Exception","\nCannot set the LOCATIONLISTENER!"+e.getMessage(),5000),gpsGui);////
    }
    return lp;
    }

    //----------------------------------------------------------------------------------------------------------//

    public void locationUpdated(LocationProvider lp, Location l) {
    try {
    paintGPSData(l);
    } catch (InterruptedException ie) {
    d.setCurrent(new Advisor("InterruptedException","\n"+ie.getMessage(),5000),gpsGui);
    }
    }

    //----------------------------------------------------------------------------------------------------------//

    public void providerStateChanged(LocationProvider lp, int newState) {
    Alert a=new Alert("GPS STATE CHANGED!");
    a.setType(AlertType.WARNING);
    a.setTimeout(3000);

    switch (newState) {
    case LocationProvider.AVAILABLE:
    a.setString("GPS IS AVAILABLE...");
    break;
    case LocationProvider.TEMPORARILY_UNAVAILABLE:
    a.setString("GPS IS TEMPORARILY UNAVAILABLE...");
    break;

    case LocationProvider.OUT_OF_SERVICE:
    a.setString("GPS IS OUT OF SERVICE...");
    break;
    }
    d.setCurrent(a,gpsGui);
    }

    //----------------------------------------------------------------------------------------------------------//
    Could you be so kind to write a snippet of your code (LocationListener methods), please?

    Thanks in advance.

  6. #6
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: Refreshing coordinates with JSR-179!

    hi,

    the only difference I could see is that I test midlet for 3250 device and Nokia GPS module obtaining location provider into separated thread (something different then you are doing I think),
    other things like listeners are simliar, I get state for valid/invalid and passs coords to different method quiting listener,
    as noted in nokia doc listener should do really nothing and exists immadiately,
    http://www.forum.nokia.com/ME_Develo...C4FA01EA5.html

    try running Nokia sample:
    http://www.forum.nokia.com/info/sw.n..._v1_0.zip.html
    on your n93 device,

    also try not using defaults for listener but increase interval time, maybe that will help,

    regards,
    Peter

  7. #7
    Regular Contributor
    Join Date
    Feb 2006
    Posts
    150

    Thumbs up Re: Refreshing coordinates with JSR-179!

    Thanks Peter for you help!

    If I have more problems I will ask you for a little of help again!

    Now my MIDlet works perfectly. The GPS receiver hasn't got coverage and the MIDlet was like freezing but when the GPS receiver caugth coverage the MIDlet worked perfectly!

    Thanks a lot!

    Summerman. :=)

Similar Threads

  1. JSR 179 - developing applications with it
    By Avengola in forum Mobile Java Tools & SDKs
    Replies: 23
    Last Post: 2013-01-11, 10:15
  2. devices supporting jsr 179
    By khristopher in forum Mobile Java General
    Replies: 15
    Last Post: 2011-09-21, 10:06
  3. Location api jsr 179 and Bluetooth GPS
    By prategiov in forum Mobile Java General
    Replies: 21
    Last Post: 2007-12-04, 23:36
  4. JSR 179 Vs QJAE
    By MananW in forum Mobile Java General
    Replies: 2
    Last Post: 2006-07-31, 18:54
  5. jsr 184 3D to 2D coordinates
    By simonhayles in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2005-09-13, 22:17

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×