setLocationListener?

Hello

I created a simple application that gets the current GPS position and displays on the screen, once the user presses the button "take place. Now I use a listener action... but the screen contains with long and lat updates on intervals. I don't want to do. I just want to get along and the lat once and display on the screen when the button is clicked.

Which method should be used to return the values that I don't need only once?

Any help will be appreciated.

Concerning

Wes

Try this

class FieldListener implements {FieldChangeListener}
longitude double private;
Private double latitude;

' Public Sub fieldChanged (field field, int context) {}
try {}
final LocationProvider lp = LocationProvider.getInstance (null);
If (lp! = null) {}
lp.setLocationListener (new GetCoordinates(), interval, 1,
// 1);
New Thread (new Runnable() {}
public void run() {}
int timeout = - 1;
try {}
A place = lp.getLocation (timeout);

Longitude = location.getQualifiedCoordinates)
. getLongitude();
Latitude = location.getQualifiedCoordinates () .getLatitude ();
} catch (LocationException e) {}
Generative TODO catch block
e.printStackTrace ();
} catch (InterruptedException e) {}
Generative TODO catch block
e.printStackTrace ();
}

}
({. start()});
                    
} else {}
Dialog.Alert ("GPS NOT supported!");
}
} catch (LocationException e) {}
System.out.println ("LocationException:" + try ());
} catch (Exception e) {}
System.out.println ("Exception:" + try ());
}
}
}

Let me know if it solves your problem

Thank you

Ankit

Tags: BlackBerry Developers

Similar Questions

  • GPS of the poll seems to block on setLocationListener

    I try to start the GPS of the poll, but setLocationListener seems to hang.  The application just hangs there.  It's on a device of Torch 9810.  I use 6 SDK.  I don't get any errors, it just seems to stop.  After MUCH research, I came up with this:

    I have static variables of provider and criteria in my main application class.

    To start the voting, the word is setupGpsPolling();

    I put a listener of the situation with my interval.

    I have a thread that checks the latest patch.  If the time is more than 20 minutes, it resets by calling setupGpsPolling();

    In my main application class:

       private static BlackBerryLocationProvider _provider = null;
        private static BlackBerryCriteria _criteria;
    ......
    
        public static void setupGpsPolling() {
            LocationInfo.setLocationOn();
            if (_provider != null) {
                _provider.setLocationListener(null, 0, 0, 0);
                _provider.reset();
                _provider = null;
            }
    
            try {
                _criteria = new BlackBerryCriteria();
                _criteria.setGPSRestartInterval(600, 0);
                _criteria.setSpeedAndCourseRequired(true);
                _provider = (BlackBerryLocationProvider) LocationProvider.getInstance(_criteria);
                _provider.setLocationListener(new LocationListener(), 300, -1, 0);
            } catch (LocationException e) {
                System.out.println(e.getMessage());
            }
        }
    

    LocationListener

    public class LocationListener implements javax.microedition.location.LocationListener{
    
        private static long lastFix = 0l;
        private static Object lock = new Object();
    
        public void locationUpdated(LocationProvider provider, Location location) {
            try {
                BlackBerryLocation loc = (BlackBerryLocation) location;
                double longitude = location.getQualifiedCoordinates().getLongitude();
                double latitude =location.getQualifiedCoordinates().getLatitude();
                float speed = location.getSpeed();
                float course = location.getCourse();
                setLastFix(location.getTimestamp());
                GPSLocation gps = new GPSLocation(longitude, latitude, speed, course, location.getTimestamp());
                gps.setStatus(loc.getStatus());
                gps.setError(loc.getError());
                gps.process();
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
        }
    
        public void providerStateChanged(LocationProvider provider, int newState) {
    
        }
    
        public static void setLastFix(long lastFix) {
            synchronized (lock) {
                LocationListener.lastFix = lastFix;
            }
        }
    
        public static long getLastFix() {
            synchronized (lock) {
                return lastFix;
            }
        }
    
    }
    

    My thread checker:

    public class GPSThread extends Thread {
    
        public GPSThread() {
        }
    
        public void run() {
            while (true) {
                try {
                    Thread.sleep(300000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if ((System.currentTimeMillis() - LocationListener.getLastFix()) > (20 * 60 * 1000)) {
                    App.setupGpsPolling(); //reset our location listener
                }
            }
    
        }
    }
    
    _provider.setLocationListener(new LocationListener(), 300, -1, 0)
    

    Should have been

    _provider.setLocationListener(new LocationListener(), 300, -1, -1)
    
  • Listener GPS problem

    Hi people,

    In collaboration with 4.2.1 on the 8800 Simulator.  My application is currently composed of two separate applications, app UI to obtain/view the information and a 'replication' application that communicates with our backend. I want to be able to include location on request of the user data (in the application user interface) and once it is updated, have replication app send it to the server. I have this work especially to my satisfaction, but the following problem: when I close the application user interface, any incomplete GPS please never finished. It seems that my LocationListener is not registered, or maybe the listener Thread is killed the closure of the part of the user interface. I don't expect that the instance is stored in the runtimestore and the object that is saved as the listener is always valid. Here's how I set it up:

    App of the user interface, the following is performed from a menu, click:

                GPSUpdater gps = GPSUpdaterFactory.getGPSUpdater();            gps.getGPSData(row, GPSUpdater.CHECK_IN);
    

    Replication App: (cut a lot of independent code)

    class ReplicationManagerImpl implements LocationListener{    private GPSUpdater mGPSUpdater;
    
        ReplicationManagerImpl()    {        mGPSUpdater = GPSUpdaterFactory.getGPSUpdater();        mGPSUpdater.setListener(this);    }
    
        public void locationUpdated(LocationProvider provider, Location location)    {        mGPSUpdater.newLocationReceived(location);    }
    
        public void providerStateChanged(LocationProvider provider, int newState)    {        //Not worried about this    }}
    

    GPSUpdater:

    public class GPSUpdater{    private Vector mUpdates;    private LocationProvider mProvider;    private Location mLocation;    private LocationListener mListener;    private Boolean isAcquiring;    private int mCounter;
    
        private static final int MAX_RETRIES = 10;    public static final int CHECK_IN = 0;    public static final int CONFIRM = 1;
    
        private static class UpdateData    {        private DataRow suRow;        private int updateType;        private long timeStamp;    }
    
        GPSUpdater()    {        Criteria criteria = new Criteria();        criteria.setHorizontalAccuracy(50);        criteria.setVerticalAccuracy(50);        criteria.setCostAllowed(false);        try        {            mProvider = LocationProvider.getInstance(criteria);            if (mProvider.getState() == LocationProvider.OUT_OF_SERVICE)            {                SubsystemLog.log("GPS actions not supported", EventLogger.ALWAYS_LOG);            }        }        catch (LocationException lEx)        {            SubsystemLog.log("Error creating LocationProvider in GPSUpdater: " + lEx.getMessage(), EventLogger.ERROR);        }        mUpdates = new Vector();        mLocation = null;        isAcquiring = Boolean.FALSE;        mCounter = 0;    }
    
        public void setListener(LocationListener listener)    {        mListener = listener;    }
    
        public void getGPSData(DataRow row, int updateType)    {        long timestamp = System.currentTimeMillis();        if (((mLocation != null) && (mLocation.isValid()) && (mLocation.getTimestamp() > timestamp - 60000)) || (mProvider == null) || (mProvider.getState() == LocationProvider.OUT_OF_SERVICE))        {            UpdateRow(row, updateType, timestamp);        }        else        {            UpdateData update = new UpdateData();            update.row = row;            update.updateType = updateType;            update.timeStamp = timestamp;
    
                synchronized(mUpdates)            {                mUpdates.addElement(update);            }
    
                synchronized(isAcquiring)            {                if (!isAcquiring.booleanValue())                {                    mProvider.setLocationListener(mListener, 5, 5, -1);                    isAcquiring = Boolean.TRUE;                }            }        }    }
    
        public void newLocationReceived(Location location)    {        if ((location == null) || (!location.isValid()) && (mCounter < MAX_RETRIES))        {            mCounter++;            return;        }
    
            mCounter = 0;        mLocation = location;        SubsystemLog.log("Acquired co-ordinates: " + Double.toString(location.getQualifiedCoordinates().getLatitude()) + "," + Double.toString(location.getQualifiedCoordinates().getLongitude()), EventLogger.DEBUG_INFO);
    
            Database db = DataSystemFactory.getDataSystem().openDatabase(DBSchema.NAME);        Object syncObject = db.getSyncObject();
    
            synchronized(syncObject)        {            while (mUpdates.size() > 0)            {                UpdateData update = (UpdateData)mUpdates.elementAt(0);                UpdateRow(update.row, update.updateType, update.timeStamp);                mUpdates.removeElement(update);            }        }        db.commitAndNotify();
    
            synchronized(isAcquiring)        {            provider.setLocationListener(null, -1, -1, -1);            isAcquiring = Boolean.FALSE;        }    }
    
        private void UpdateRow(DataRow suRow, int updateType, long timeStamp)    {        //wrapper class to allow persisting double values        DBDouble latitude = new DBDouble();        DBDouble longitude = new DBDouble();
    
            if (mLocation != null && mLocation.isValid())        {            latitude.setDouble(mLocation.getQualifiedCoordinates().getLatitude());            longitude.setDouble(mLocation.getQualifiedCoordinates().getLongitude());        }        else        {            latitude.setDouble(0.0);            longitude.setDouble(0.0);        }
    
            //store data here    }
    
    }
    

    GPSUpdaterFactory:

    public abstract class GPSUpdaterFactory {    private static final long ID = ;
    
        public static final GPSUpdater getGPSUpdater()    {        Object o;        GPSUpdater gpsUpdater = null;        RuntimeStore runtimeStore = RuntimeStore.getRuntimeStore();        synchronized (runtimeStore)        {            o = runtimeStore.get(ID);            if (o != null)            {                if (o instanceof GPSUpdater)                {                    gpsUpdater = (GPSUpdater)o;                }            }            if (gpsUpdater == null)            {                gpsUpdater = new GPSUpdater();                runtimeStore.put(ID, gpsUpdater);            }        }        return gpsUpdater;            }}
    

    Any suggestions are greatly appreciated.

    Thank you

    Mike

    Notice that the menu close item also called System.exit.

    In this case the application would stop receiving updates following the call of output.  To work around this problem, you can call Application.requestBackground.  This moves the application in the background, where it can continue to operate.  Once you have your final fix application can call System.exit to close itself.

  • Explanation of position of provider.

    Hi guys,.

    When you use the location provider I did the following:

    _locationProvider.setLocationListener(new LocationListenerImpl(), 300, 15, 10);
    

    My question is to do with variables passed:

    int interval,
    int timeout,
    int maxAge
    

    Interval is set to 300 seconds, this means the location provider "awakens" after five minutes and gets a single position report, or is he constantly updated?

    Timeout, this is the time in seconds, the GPS chip to get a report after five minutes? Age Max, this should be more OLD than timeout? because if the time-out is 15 (which means that the chip GPS CAN get a report within the first 4 seconds) and the maxAge is 10 (whatever it is over 10 seconds is deleted) a location received within the first 4 seconds would be ignored?

    To anwer my own question:

    With this, it is possible to define the following

    parameters: interval (in seconds) during which the application wants to receive events. the time-out period

    value that indicates how the end (in seconds) an update must be compared to the definition

    interval; the value of maxage, which defines at what age the update location value should be.

  • TimerTasks battery drain!

    Hi gurus

    I am developing a project that has 2 main parts: the graphical interface and a background process. I do this with the help of another point of entry for the GUI. The background process starts automatically and the GUI is started using an application icon.

    What is the background process is 3 things:

    1. GPS location of the registry every 10 minutes
    2. Send GPS positions stored each hour to consume a web service (HttpConnection)
    3. Check if the user has saved records and send them to a server with the web services every hour.

    Sorry haven't looked hard to your code, but I see nothing that resets the LocationListener.  So I wonder if in fact the GPS is disabled?

    Memory, to stop a LocationListener, you need to do

    mLocProvider.setLocationListener (null, 1, 1, 1);

    I could be wrong, but I don't think that canceling the TimerTask will do that.

    I understand that there is advantage also made a getLocation() before departure using a LocationListener, to make sure that the GPS actually works.  But it would make your TimerTask blocking, and I'm not sure you want to do.

  • GPS latitude and longitude are not when no signal

    Hello

    I am buliding a BB 9700 GPS application. I am able to get the latitude and longitude through cellTower (using the Service Provider signal), but I am unable to get the latitude and longitude when there is no signal. I tried the criteria to false, but the lattude and longitude do not come.

    Please find the code below

    private LocationProvider _provider;
    private Criteria _criteria;
    boolean deviceReciever,cellSignal;
    
    String longitude, latitude,altitude,speed;
    
    private void FixLocation()
    {
          resetProvider();
          /** Initialize Criteria and LocationProvider instances. */
    
          deviceReciever = true;//receiving lattitude and longitude to phone gps reciever
          cellSignal; = false;//Disabling ph signals
    
          setupCriteria();
          createLocationProvider();
    
                   if(_provider!=null){
    
                      try{
                       _location = _provider.getLocation(5);
                     locationUpdated(_provider, _location);
                     }catch(InterruptedException e){
                            //log(e.getMessage());
                            System.out.println("Exception called --->"+e);
                       }catch(LocationException e)
                       {
                               //log(e.getMessage());
                               System.out.println("Exception called --->"+e);
                       }
                       /*-->
                       try
                       {
                            System.out.println("babaji");
                            System.out.println("The _interval="+_interval);
                            _interval = -1;
                            _provider.setLocationListener(this, _interval, 10, 20);
                       }
                       catch(Exception e)
                       {
                           System.out.println("Exception called-->"+e);
                       }
                       */
                   }
    
           }
    
        private void resetProvider()
        {
            if (_provider != null)
           {
              _provider.setLocationListener(null, 0, 0, 0);
              _provider.reset();
              _provider = null;
            }
         }
    
          private void setupCriteria()
          {
                _criteria = new Criteria();
                if( deviceReciever == true )
                {
                    _criteria.setCostAllowed(false);
    
                }
               else if( cellSignal == true )
                {
    
                    _criteria.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);
                    _criteria.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
                    _criteria.setCostAllowed(true);
                    _criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);
                }
           }
    
        private void createLocationProvider()
       {
                    /**
                 * Initialize _provider using _criteria.
                    */
                try
                {
                     _provider = LocationProvider.getInstance(_criteria);
                }
                catch (LocationException e)
                {
    
               }
          }
    
         public void locationUpdated(LocationProvider provider, Location location)
        {
                 if (location != null && location.isValid())
                 {
    
                      QualifiedCoordinates coordinates = location
                                        .getQualifiedCoordinates();
    
                        speed = Float.toString(location.getSpeed());
                        longitude = Double.toString(coordinates.getLongitude());
                        latitude = Double.toString(coordinates.getLatitude());
                        altitude = Float.toString(coordinates.getAltitude());
    
                        System.out.println("Longitude --->"+coordinates.getLongitude());
                        System.out.println("Latitude---->"+coordinates.getLatitude());
                        System.out.println("Altitude->"+coordinates.getAltitude());
                    }
    
         }
    

    The longitude and latitude are coming as null always if we I'm reciving the gps via the mobile gps receiver. If the signal of the mobile service provider then uses the lang and lat come.

    I don't want to use the service provier signal for lattitude and longitude.

    Please suggest me the error I made in the above code and assistance.

    Thanking you

    Standalone GPS works best outdoors, with a clear view of the sky.  At the very least, near a window.

    You can experiment with the timeout.

    (If these answers answer your question, please mark the thread as solved.  (Thank you).

  • GPS returns for speed and longitude 0.0

    I get 0.0 for the speed (except NaN invalid) and longitude.  Latitude and journey to return a valid number. It's on a Torch 9810 OS7 but the app is defined for the OS6.  Look in the console attached through Eclipse,

    public class LocationListener implements javax.microedition.location.LocationListener{
    
        private static long lastFix = 0l;
        private static Object lock = new Object();
    
        public void locationUpdated(LocationProvider provider, Location location) {
            try {
                BlackBerryLocation loc = (BlackBerryLocation) location;
                double longitude = 0d;
                double latitude = 0d;
                if (loc.getQualifiedCoordinates() != null) {
                    longitude = loc.getQualifiedCoordinates().getLongitude();
                    latitude = loc.getQualifiedCoordinates().getLatitude();
                }
                float speed = loc.getSpeed();
                float course = loc.getCourse();
                setLastFix(loc.getTimestamp());
                GPSLocation gps = new GPSLocation(longitude, latitude, speed, course, (loc.getTimestamp() == 0l ? System.currentTimeMillis() : loc.getTimestamp()));
                gps.setValid(loc.isValid());
                gps.setStatus(loc.getStatus());
                gps.setError(loc.getError());
                gps.print();
                App.addToPool(gps);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public void providerStateChanged(LocationProvider provider, int newState) {
            if (newState == LocationProvider.TEMPORARILY_UNAVAILABLE) {
                provider.reset();
                provider.setLocationListener(null, 0, 0, 0);
            }
            App.setupGpsPolling();
        }
    
        public static void setLastFix(long lastFix) {
            synchronized (lock) {
                if (lastFix != 0l)
                    LocationListener.lastFix = lastFix;
            }
        }
    
        public static long getLastFix() {
            synchronized (lock) {
                return lastFix;
            }
        }
    
    }
    
    public class GPSLocation {
        ......
        public void print() {
            StringBuffer sb = new StringBuffer();
            sb.append("longitude: " + getLongitude()).append("\r\n");
            sb.append("latitude: " + getLatitude()).append("\r\n");
            sb.append("speed: " + getSpeed()).append("\r\n");
            sb.append("course: " + getCourse()).append("\r\n");
            sb.append("ts: " + getTimestamp()).append("\r\n");
            sb.append("stat: " + getStatus()).append("\r\n");
            sb.append("err: " + getError()).append("\r\n");
            sb.append("valid: " + isValid()).append("\r\n");
            System.out.println(sb.toString());
        }
        ......
    }
    

    I don't understand.  Do works that way.

               QualifiedCoordinates coor = location.getQualifiedCoordinates();
                if (coor != null) {
                    longitude = coor.getLongitude();
                    latitude = coor.getLatitude();
                    }
    
  • Cannot find the location of the gps on the device

    in my application, I'm trying to find the location of the user.my code owrks in Simulator for the curve8300 and the 9000 "BOLD"

    but he does not get the cordinates on the device even though I update the gps manually using the options--> options--> gps.

    What to do

     package com.MyChamberApp;
    
        import javax.microedition.location.Criteria;
        import javax.microedition.location.Location;
        import javax.microedition.location.LocationListener;
        import javax.microedition.location.LocationProvider;
    
        public class GPS_Location {
         static double longi;
         static double lati;
    
         public GPS_Location() {
    
         }
    
         public void location()
         {
          new LocationTracker();
         }
    
         class LocationTracker
         {
          private LocationProvider provider;
          Criteria cr;
    
          public LocationTracker()
          {
           resetGPS();
          }
    
          public void resetGPS() {
    
          try {
          cr = new Criteria();
          cr.setPreferredPowerConsumption(Criteria.POWER_USAGE_HIGH);
          cr.setPreferredResponseTime(120000);
                    cr.setCostAllowed(true);
          provider = LocationProvider.getInstance(cr);
          provider.getLocation(120);
          if (provider != null)
           {
            provider.setLocationListener(new MyLocationListener(), 1,1,1);
           }
          } catch (Exception e) {}
    
          }
    
          public void run(){}
    
         private class MyLocationListener implements LocationListener
             {
           public void providerStateChanged(LocationProvider provider,int newState)
           {
            if (newState == LocationProvider.TEMPORARILY_UNAVAILABLE)
            {
              provider.reset();
              resetGPS();
            }
           if (newState == LocationProvider.OUT_OF_SERVICE)
           {
            provider.reset();
            resetGPS();
           }
         }
    
         public void locationUpdated(LocationProvider provider,Location location)
          {
           if (location != null && location.isValid()) {
            try {
          lati = location.getQualifiedCoordinates().getLatitude();
          longi = location.getQualifiedCoordinates().getLongitude();
             } catch (Exception e) {}
         }
          }
        }
       }
     }
    

    Although the code seems fine for me, check with this code...

    Criteria criteria = new Criteria();
    
    criteria.setHorizontalAccuracy(50);
                criteria.setVerticalAccuracy(50);
                criteria.setCostAllowed(true);
                criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_HIGH);
                _locationProvider = LocationProvider.getInstance(criteria);
                  Location location =_locationProvider.getLocation(-1);
                _longitude = location.getQualifiedCoordinates().getLongitude();
                _latitude = location.getQualifiedCoordinates().getLatitude();
                 _altitude = location.getQualifiedCoordinates().getAltitude();
                 _speed = location.getSpeed();
                if(_locationProvider!=null)
                 {
                  _locationProvider.setLocationListener(new LocationListenerImpl(), _interval, 1, 1);
    
                }
    
  • How to use LocationCoder

    my snippet of location provider does not work. I imported the required packages. It gives an error, but this method is not applicable for these parameters. I don't have any idea what means this error

    {lp = LocationProvider.getInstance(null);
    lp.setLocationListener(ll, 1, 1, 1);}
    

    http://supportforums.BlackBerry.com/T5/Java-development/location-APIs-start-to-finish/Ta-p/571949

    also

    http://supportforums.BlackBerry.com/T5/Java-development/simple-location-API/Ta-p/1145951

  • Different ways to reset the LocationProvider in the article?

    Hi guys.

    I'm confused about LocationProvider reset in the statutes.

    So, first of all:

    This article on:

    How to-detect when the GPS is no longer available and the moment reset the LocationProvider

    There are way to reset LocationProvider:

    Step 2: reset the LocationProvider

    Once the detection is complete, the next step is the LocationProvider reset. To do this, simply call reset() on LocationProvider instance, and then set either LocationListener null, or register a new LocationListener.

    It is just like in the code:

    locationProvider.reset ();

    locationProvider.setLocationListener (null, 0, 0, 0);
    locationProvider = null; I am not persuaded that this line.

    locationProvider.setLocationListener (new LocationListenerImpl(), 0, 0, 0);

    Second,

    This article on:

    What's – best practices for the design of GPS applications for smartphones BlackBerry running on CDMA Networks

    There is a code that LocationProvider everything like reset:

    provider.setLocationListener (null, 0, 0, 0);
    Provider.Reset ();
    Provider = null;
    Provider = LocationProvider.getInstance (criteria);
    provider.setLocationListener (new LocationListenerImpl (), interval, timeout, maxAge);

    What is the correct code?  First or second?

    Please help me guys.

    Thanks in advance.

    If I was coding it again, I would

    provider.setLocationListener (null, 0, 0, 0);
    Provider.Reset ();
    Provider = null;

  • GPS Timed Out error when querying location

    Hi all

    I worked with GPS and maps on BlackBerry OS 5.0 and it has been frustrating to say the least.  I have everything working, however I get an error 'GPS timed' out whenever I try to question my location.  I get this error on a real device, and not on the Simulator.  This happens for a MapField both the native BlackBerry map.

    Essentially, what I'm doing is looking for the current coordinates via GPS, translating these coordinates in an address through reverseGeocoding (a separate thread) and then using that zip code to find and locate a web service.  The web service to function properly, it is the GPS which is the problem.

    I'd appreciate it if someone could take a look at my code and see if something comes out.  Here's my LocationHandler (implementation of LocationListener):

    import javax.microedition.location.Criteria;
    import javax.microedition.location.Location;
    import javax.microedition.location.LocationException;
    import javax.microedition.location.LocationListener;
    import javax.microedition.location.LocationProvider;
    import javax.microedition.location.QualifiedCoordinates;
    import com.usps.mobile.blackberry.Constants;
    import com.usps.mobile.blackberry.Inform;
    import com.usps.mobile.blackberry.interfaces.ScreenLocation;
    
    public class LocationHandler extends Thread implements LocationListener {
        private ScreenLocation screen;
        private boolean periodicUpdates;
    
        public LocationHandler(ScreenLocation screen, boolean update) {
            this.screen = screen;
            this.periodicUpdates = update;
        }
    
        public void locationUpdated(LocationProvider provider, Location location) {
            QualifiedCoordinates qualifiedCoordinates = location
                    .getQualifiedCoordinates();
    
            int longitude = (int) (qualifiedCoordinates.getLongitude() * 1000000);
            int latitude = (int) (qualifiedCoordinates.getLatitude() * 1000000);
            new myReverseGeocode(longitude, latitude, screen);
        }
    
        public void providerStateChanged(LocationProvider provider, int newState) {
            // So far, nothing for this
        }
    
        /**
         * The thread
         */
        public void run() {
            Criteria criteria = new Criteria();
            criteria.setVerticalAccuracy(Constants.DEFAULT_VERTICAL_ACCURACY);
            criteria.setHorizontalAccuracy(Constants.DEFAULT_HORIZONTAL_ACCURACY);
            criteria.setCostAllowed(true);
            criteria
                    .setPreferredPowerConsumption(Constants.DEFAULT_GPS_POWER_CONSUMPTION);
    
            try {
                LocationProvider provider = LocationProvider.getInstance(criteria);
                Location location = provider.getLocation(-1);
    
                locationUpdated(provider, location);
                if (periodicUpdates) {
                    // Update every 1 minute
                    provider.setLocationListener(this, 60, -1, 10);
                }
            } catch (final LocationException e) {
    
                Inform.inform(e.getMessage());
    
                screen.setLocation(Constants.DEFAULT_LONGITUDE,
                        Constants.DEFAULT_LATITUDE);
            } catch (final InterruptedException e) {
    
                Inform.inform(e.getMessage());
    
                screen.setLocation(Constants.DEFAULT_LONGITUDE,
                        Constants.DEFAULT_LATITUDE);
            }
        }
    
    }
    

    Method setLocation in my main screen:

    public void setLocation(int longitude, int latitude, AddressInfo addrInfo) {
            synchronized (UiApplication.getEventLock()) {
                mapField.moveTo(latitude, longitude);
    
                mapField.setZoom(Math.max(mapField.getZoom() - 1, mapField
                        .getMinZoom()));
    
                doWebService(addrInfo.getField(AddressInfo.POSTAL_CODE));
            }
        }
    

    As I said, reverseGeocode() is on its own thread, and it's back a correct information.

    Thank you!

    On verizon.

    You will not be able to be assisted without access PDE.   The criteria that you have shown, is not mapped to stand alone.

    Autonomous may take some time to get and quite well must have a clear view of the sky for correct performance.

  • Problem stop LocationListener

    Hello guys '

    My development proposal has associated GPS module. In this module, I am facing this problem.

    IE when stops and starts LocationListener, sometimes it can work and sometimes it does not.

    I use to start and stop LocationListener following code:

    private class GpsInternal implements LocationListener {
    
            LocationProvider lp;
    
            public GpsInternal() {      lp = null;    }
    
      public boolean isConnected() {        return (lp != null);  }
    
      public void start() {     if (lp == null) {         try {         lp = LocationProvider.getInstance(null);          if(lp != null) {          lp.setLocationListener(this, _interval, -1, -1);          }         } catch(LocationException e) {                }         }     }
    
      public void stop() {      if (lp != null) {         lp.reset();           lp.setLocationListener(null, -1, -1, -1);         lp = null;            }     }
    
      public void locationUpdated(LocationProvider provider, Location location) {
    
      if(location.isValid()) {  double longitude = location.getQualifiedCoordinates().getLongitude(); double latitude = location.getQualifiedCoordinates().getLatitude();   float altitude = location.getQualifiedCoordinates().getAltitude();        } }
    
      public void providerStateChanged(LocationProvider provider, int newState) {       //Nothing }}
    

    I think that the start() method has no problem. And the stop() method has something wrong. But I don't know what it is.

    If you have the idea to start and stop LocationListener, please share with me.

    TNX all '

    Try the lp.reset () after the lp.setLocationListener (null,-1, -1, -1).

    It's the way that I do and have not had any problems.

  • getLocation question

    My app uses the GPS demo code and seeks to acquire the location using cellsites.

    I see two problems:

    1. the code works on a 9550 Simulator, but does not return an a call from getLocation(-1) on a Bold 9700 device

    2. when in setupCriteria that I use, the code is suspended on this line.

    The pointers will be appreciated.

    Thank you

    //myCriteria = new BlackBerryCriteria(GPSInfo.GPS_MODE_CELLSITE);
    

    The code looks like this:

    private void setupCriteria(){
        _criteria = new Criteria();
        _criteria.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);
        _criteria.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
        _criteria.setCostAllowed(true);
        _criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);
        //myCriteria = new BlackBerryCriteria(GPSInfo.GPS_MODE_CELLSITE);
    }
    
    private void createLocationProvider(){
        try {
            _provider = LocationProvider.getInstance(myCriteria);
        } catch (LocationException e) {
            status("Error in location acquisition");
        }
    }   
    
    private void getSingleFix(){
        new Thread(){
            public void run(){
                   resetProvider();
                setupCriteria();
                createLocationProvider();
                try {
                _location =_provider.getLocation(-1);         } catch (LocationException e) {
                status("Error in location acquisition");
                } catch (InterruptedException e) {
                status("Error in location acquisition");
                }
    
                if(_location!=null && _location.isValid()){
                QualifiedCoordinates coordinates = _location.getQualifiedCoordinates();
                double lat = coordinates.getLatitude();
                double longit = coordinates.getLongitude();
                latlong(lat, longit);               status(" ");
                    log("In loc valid");
    
                } else{
                    status("Error in location acquisition");
                }
            }
        }.start();
    }
    private void resetProvider(){
        if(_provider!=null){
            _provider.setLocationListener(null, 0, 0, 0);
            _provider.reset();
            _provider=null;
        }
    }
    
    public void locationUpdated(LocationProvider provider, Location location) {
        if(location!=null && location.isValid()){
            QualifiedCoordinates coordinates = location.getQualifiedCoordinates();
            double lat = coordinates.getLatitude();
            double longit = coordinates.getLongitude();
            latlong(lat, longit);
            status(" ");
        } else{
            status("Error in location acquisition");
        }
    }
    
    public void providerStateChanged(LocationProvider provider, int newState) {
            /**
             * not implemented. For more information on how to implement this method please
             * refer to the BlackBerry Developer Knowledge Base Articles.
             */
    
    }
    

    Try to set to high energy consumption and see if it works.

    My GPS application appears to hang or throw a null pointer exception when I try to use Power Consumptin set to low temperature on my BB 9700.

    () criteria.setPreferredPowerConsumption

    Criteria.POWER_USAGE_HIGH);

  • BlackBerryLocation.getSatelliteInfo () returns a null value

    The method always returns null. Valid GPS locations are acquired, with the no. satellites given as well. I want to determine the quality of the satellite signal, I'd really like the detailed satellite information.

    As explained in a thread on this issue by another poster, I used the following method to allow information by Satellite:

    BlackBerryCriteria.setSatelliteInfoRequired (true, false);

    I tried the method of getSatelliteInfo() on the following devices.

    -Bold 9000 (5.00.1036)

    -Torch 9800 (6.0.0.246)

    The code is below.

    Any help would be greatly appreciated.

    Simon

                BlackBerryCriteria myCriteria = new BlackBerryCriteria(GPSInfo.GPS_MODE_AUTONOMOUS);
                myCriteria.setSatelliteInfoRequired(true, false);
    
                try
                {
                    BlackBerryLocationProvider myProvider =
                      (BlackBerryLocationProvider)
                        LocationProvider.getInstance(myCriteria);
    
                    try
                    {
                        BlackBerryLocation myLocation =
                          (BlackBerryLocation)myProvider.getLocation(300);
    
                        satCount= myLocation.getSatelliteCount();
                        signalQuality =
                          myLocation.getAverageSatelliteSignalQuality();
                        dataSource = myLocation.getDataSource();
                        gpsMode = myLocation.getGPSMode();
    
                        SatelliteInfo si;
                        StringBuffer sb = new StringBuffer("[Id:SQ:E:A]\n");
                        String separator = ":";
    
                        for (Enumeration e = myLocation.getSatelliteInfo();
                          e!=null && e.hasMoreElements(); )
                        {
                            si = (SatelliteInfo)e.nextElement();
                            sb.append(si.getId() + separator);
                            sb.append(si.getSignalQuality() + separator);
                            sb.append(si.getElevation() + separator);
                            sb.append(si.getAzimuth());
                            sb.append('\n');
                        }
                    }
                    catch ( InterruptedException iex )
                    {
                        return null;
                    }
                    catch ( LocationException lex )
                    {
                        return null;
                    }
                }
                catch ( LocationException lex )
                {
                    return null;
                }
    

    To obtain the information by satellite, a LocationListener must be put in place to wait for notifications in a separate thread by implementing the locationUpdated(). Please take a look at the LocationProvider class to see how setLocationListener.

  • GPS location. IsValid() always false.

    I did some research and reading, but do not have a good understanding of the way which he GPS libraries works (or why it doensn can't work properly for me )

    provider init code

    public static LocationProvider getLocationProvider(){
                LocationProvider locationProvider = null;
                try{
                    Criteria criteria = new Criteria();
                    criteria.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);
                    criteria.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
                    criteria.setCostAllowed(false);
                    criteria.setPreferredPowerConsumption(Criteria.NO_REQUIREMENT);
    
                    locationProvider = LocationProvider.getInstance(criteria);
                }catch (LocationException le){
                    locationProvider = null;
                }
    
                 return (locationProvider);
            }
    

    define a listener (5 minutes interval):

    locationProvider.setLocationListener(new LocationListenerImpl(), 5 * 60, -1, -1);
    

    listener:

      if(location.isValid()){
                                                                                        longitude = location.getQualifiedCoordinates().getLongitude();
                                latitude = location.getQualifiedCoordinates().getLatitude();
                                                        }
                            else{
                                if (_unvalidFixes++ == 3){
                                                                    ResetProvider(provider,5));
                                    _unvalidFixes = 0;
                                }
                                                        }
    

    Reset

     private void ResetProvider(LocationProvider provider, int IntervalInMinutes){
                                provider.setLocationListener(null,0,0,0);
                    provider.reset();
                    try {
                        Thread.sleep(20000);
                    } catch (Exception e) {
                        LogFile.WriteLogEntry("LocationListenerImpl.ResetProvider: Sleep Exception", LogFile._DEBUG);
                    }
                    provider.setLocationListener(this, IntervalInMinutes * 60, -1, -1);
    
                }
    

    providerStateChanged (never shot...)

      public void providerStateChanged(LocationProvider provider, int newState)
                {
                    AppSettingsStorage appSettingsStorage = AppSettingsStorage.getInstance();
    
                    switch (newState) {
                                            case LocationProvider.TEMPORARILY_UNAVAILABLE:  
    
                            ResetProvider(provider,5
                            break;
                    }
    
                }
    

    the result of this code is that location.isValid ()) is always wrong, and I don't know why ,.

    Thank you!

    I've implemented my own thread getLocation and use (such as Peter suggested on thread referenced..) and now it works fine,

    I have a thing for big (I don't know which size - 5 minutes in my case-) intervals is a better alternative...

    (or maybe a good understanding of the parameters of setLocationListener...) ),

Maybe you are looking for

  • Satellite Pro L550 - Realtek RTL8191SE Wlan connection issues

    Hello Affected by a big problem with my WLAN connection which is ongoing for about a month.I have problems with a very inconsistent connection. To start, turn on the laptop of its climate 50-50 I'll successfully connect to my internet. Once connected

  • My entire office and saved files were deleted from my computer. I don't know what happened

    When I started my computer this morning everything on my desktop disappeared and I got a black screen. All the icons on my task pane were still missing. I can't find the saved files. Help, please

  • PSG could not install on PC

    I just bought a buy.com SanDisk mp3 player, when I plug it into the computer it says THAT PSG failed to install, how can I get my computer in order to install correctly my c240 San Disk drive?Thank you very much and happy holidays! BTW, I'm using win

  • MultiStream in TC 7.3

    How can I enable multistream on the endpoints supported?  According to the telepresence Server Software Release Notes (4.1 (1.85)) the feature is experimental and is not enabled by default, but it say anywhere how to activate it.  No mention of the f

  • Is there a way to get around to enter a password? Windows 7 Home Premium for elderly

    I got a new Dell with Windows 7 Home Premium for my widowed father age of 75 year. He hates absolutely for click the user and type a password whenever he lights the thing... especially if it's just to play games offline like Spider Solitaire. Is ther