Sorry about the red box, but we really need you to update your browser. Read this excellent article if you're wondering why we are no longer supporting this browser version. Go to Browse Happy for browser suggestions and how to update.

Retrieving a location using GPS

Your apps can retrieve the GPS location of a BlackBerry device. The values for the location information are returned as coordinates for latitude, longitude, and altitude.

You can specify the following GPS modes: autonomous mode, assisted mode, and cell site mode. The GPS mode can affect the initial speed of a GPS fix and the level of location accuracy. For example, a weather application might specify cell site mode, which can quickly provide an approximate location. For more information about the BlackBerry device models and their available corresponding GPS modes, see BlackBerry smartphone models and their corresponding GPS capabilities .

To retrieve location information you can use the Location API, which is made up of the Location API for Java ME (JSR 179), provided in the javax.microedition.location package, and the BlackBerry extension to JSR 179 in the net.rim.device.api.gps package.

The JSR 179 Location API for Java ME is supported on BlackBerry devices that run BlackBerry Device Software 4.0.2 or later.

The extensions to JSR 179 are supported on BlackBerry devices that run BlackBerry Device Software 5.0.0 or later.

Retrieving the GPS location of a BlackBerry device involves the following actions:

  • Specify the GPS mode. For example:

    /* JSR 179 */
    Criteria myCriteria = new Criteria();
    
    /* BlackBerry extension to JSR 179 */
    BlackBerryCriteria myBlackBerryCriteria = new BlackBerryCriteria(…);
  • Retrieve a location provider. For example:

    /* JSR 179 */
    LocationProvider myProvider = LocationProvider.getInstance(myCriteria);
    
    /* BlackBerry extension to JSR 179 */
    BlackBerryLocationProvider myBlackBerryProvider =
        (BlackBerryLocationProvider) LocationProvider.getInstance(myBlackBerryCriteria);
  • Make a GPS request that is based on the frequency of the GPS fix. For example:

    /*
     * Single GPS fix
     */
    /* JSR 179 */
    Location myLoc = myProvider.getLocation(…);
    
    /* BlackBerry extension to JSR 179 */
    BlackBerryLocation myBlackBerryLoc = myBlackBerryProvider.getLocation(…);
    
    /*
     * Continuous GPS fixes
     */
    /* JSR 179 */
    myProvider.setLocationListener(…);
    
    /* BlackBerry extension to JSR 179 */
    myBlackBerryProvider.setLocationListener(…);
  • Retrieve the GPS location of a BlackBerry device. For example:

    /* JSR 179 */
    double lat = myLoc.getQualifiedCoordinates().getLatitude();
    
    /* BlackBerry extension to JSR 179 */
    double lat = myBlackBerryLoc.getQualifiedCoordinates().getLatitude();