GPS overview

You can allow a BlackBerry® device application to retrieve the GPS location of a BlackBerry device. The values for the location information are returned as the coordinates for latitude, longitude, and altitude.

The GPS mode that you specify to retrieve the location information depends on the type of application that you want to develop. The GPS modes include the 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 a cell site mode, which can quickly provide an approximate location. For more information about the BlackBerry device models and their available corresponding GPS modes, visit http://www.blackberry.com/knowledgecenterpublic/ to read article DB-00615.

To retrieve location information, you can use the JSR 179 Location API for Java® ME in the javax.microedition.location package, or the BlackBerry extension to JSR 179 in the net.rim.device.api.gps package.

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

The BlackBerry extensions to JSR 179 is 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:

  • Specifying the GPS mode
  • Retrieving a location provider
  • Making a GPS request that is based on the frequency of the GPS fix
  • Retrieving the GPS location of a BlackBerry device

Code sample: Specifying the GPS mode

/* JSR 179 */
Criteria myCriteria = new Criteria();

/* JSR 179 extension */
BlackBerryCriteria myBlackBerryCriteria = new BlackBerryCriteria(…);

Code sample: Retrieving a location provider

/* JSR 179 */
LocationProvider myProvider = LocationProvider.getInstance(myCriteria);

/* JSR 179 extension */
BlackBerryLocationProvider myBlackBerryProvider =
    (BlackBerryLocationProvider) LocationProvider.getInstance(myBlackBerryCriteria);

Code sample: Making a GPS request that is based on the frequency of the GPS fix

/*
 * Single GPS fix
 */
/* JSR 179 */
Location myLoc = myProvider.getLocation(…);

/* JSR 179 extension */
BlackBerryLocation myBlackBerryLoc = myBlackBerryProvider.getLocation(…);

/*
 * Continuous GPS fixes
 */
/* JSR 179 */
myProvider.setLocationListener(…);

/* JSR 179 extension */
myBlackBerryProvider.setLocationListener(…);

Code sample: Retrieving the GPS location of a BlackBerry device

/* JSR 179 */
double lat = myLoc.getQualifiedCoordinates().getLatitude();

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

Was this information helpful? Send us your comments.