Detect when GPS is no longer available and when to reset the LocationProvider

by Retired ‎02-16-2010 03:40 PM - edited ‎09-16-2010 03:19 PM (4,684 Views)



This article applies to the following:

  • BlackBerry® devices with built-in Global Positioning System (GPS) functionality
  • BlackBerry Device Software 4.2 and later
  • BlackBerry Java® Development Environment (JDE) 4.0.2 and later





BlackBerry devices supporting Java Specification Program (JSR) 179 have the capability to return GPS fixes to the calling application. With current GPS technology, fixes are not 100% reliable. If there is dense cloud cover or an obstructed view of the sky, autonomous GPS fixes may fail. If there is poor network coverage, assisted and cellsite GPS fixes may fail. The application developer should be ready to deal with such situations.


Step 1: detection


The only sure way to know if GPS fixes are no longer available is to implement the LocationListener and detect providerStateChanged() events. All other heuristics, such as 3 invalid fixes in a row, should not be followed since they can be triggered by other occurrences such as timeouts. The providerStateChanged() method is called by the underlying implementation if and only if the GPS chip has completed three full searches and was unable to get a fix. The time involved in completing a full search can be as long as 2 or 3 minutes. Once the three full searches have completed, providerStateChanged() will be called with newState having the value LocationProvider.TEMPORARILY_UNAVAILABLE.


Once this event has been received, the GPS chip will assume that fixes are unavailable, and in an effort to preserve battery life, will no longer attempt to acquire fixes and will instead begin returning invalid fixes


Note: Only on BlackBerry devices not supporting GPS will the state LocationProvider.OUT_OF_SERVICE, (i.e. permanently unavailable), ever be returned.


Step 2: resetting the LocationProvider


Once detection is complete, the next step is resetting the LocationProvider. To do so, simply call reset() on the instance of LocationProvider, then either set the LocationListener to null, or register a new LocationListener. Once done, the GPS chip will attempt one more complete scan before again returning the value LocationProvider.TEMPORARILY_UNAVAILABLE and falling back into the mode where it does not make any attempts.


If the TEMPORARILY_UNAVAILABLE event is again received, the application developer should assume that the BlackBerry device user is in a position where fixes cannot be acquired. The BlackBerry device user should be informed of this fact and the application can either wait for a fixed period of time before resetting the LocationProvider again or the application can wait for the BlackBerry device user to instruct the application to re-attempt the acquisition of GPS fixes.


Note: If the application developer wants the LocationProvider to attempt three full scans before returning another TEMPORARILY_UNAVAILABLE event, then reset() should be called on the current LocationProvider, any LocationListeners should be nulled out, and then the developer should request a new LocationProvider via the getInstance() method.



Additional Information


For more information on the types of GPS fixes available (autonomous, assisted, cellsite, Bluetooth), please see articles DB-00461 and DB-00538.