Retrieve location information from the GPS receiver on a BlackBerry device

  1. Import the following classes:
    • javax.microedition.location.LocationProvider
    • javax.microedition.location.Criteria
  2. Create an instance of a Criteria object.
    Criteria criteria = new Criteria();
  3. Complete one of the following tasks to get location information using the GPS receiver on a BlackBerry device:

    Task

    Steps

    Specify a level of accuracy, with no cost and no power consumption.

    1. Invoke criteria.setHorizontalAccuracy(int accuracy) using an integer value that represents the accuracy, in meters.
    2. Invoke criteria.setVerticalAccuracy(int accuracy) using an integer value that represents the accuracy, in meters.
    3. Invoke criteria.setCostAllowed(false).

    Specify a level of accuracy, with cost and variable power consumption.

    1. Invoke criteria.setHorizontalAccuracy(int accuracy) using an integer value that represents the accuracy, in meters.
    2. Invoke criteria.setVerticalAccuracy(int accuracy) using an integer value that represents the accuracy, in meters.
    3. Invoke criteria.setCostAllowed(true).
    4. Invoke criteria.setPreferredPowerConsumption(int level) using either POWER_USAGE_LOW, POWER_USAGE_MEDIUM, or NO_REQUIREMENT as the parameter.

    Specify a level of accuracy, with no cost and variable power consumption.

    1. Invoke criteria.setHorizontalAccuracy(NO_REQUIREMENT).
    2. Invoke criteria.setVerticalAccuracy(NO_REQUIREMENT).
    3. Invoke criteria.setCostAllowed(false).
    4. Invoke criteria.setPreferredPowerConsumption(int level) using either POWER_USAGE_MEDIUM, POWER_USAGE_HIGH, or NO_REQUIREMENT as the parameter.
  4. Invoke LocationProvider.getInstance() and store the returned object in a LocationProvider object.
    LocationProvider provider = LocationProvider.getInstance(criteria);

Was this information helpful? Send us your comments.