Would you like to tell us how we are doing?

You bet No thanks

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.

Finding a location

Turning on and querying Location Services on the device

The Location Services option on the BlackBerry device controls the availability of location data. When the Location Services option is turned on, you can retrieve location information from any available location source (internal GPS receiver, external GPS receiver, or geolocation). When the Location Services option is turned off, location information is unavailable.

You can check if the Location Service option is turned on by invoking LocationInfo.isLocationOn(), which is provided in the net.rim.device.api.gps package. If the option is not turned on, you can programmatically turn it on by invoking LocationInfo.setLocationOn(). To turn on the Location Services option, your app must be signed and it must have permission to change the settings on the device. Make sure your app prompts the BlackBerry device user for permission to turn on Location Services.

When you invoke setLocationOn(), the following actions take place:

  • If the Location Services option is turned off, the option is turned on, location data from GPS becomes available, if the device supports GPS technology and the IT policy on the BlackBerry Enterprise Server permits access to the GPS feature.
  • Location data from the geolocation service becomes available if the Location Data option on the BlackBerry device is enabled, the IT policy on the BlackBerry Enterprise Server permits access to the geolocation service, and the wireless service provider permits access to the service.
  • For external GPS receivers, location data becomes available if the external receiver is specified as the current GPS Data Source (in the Options on the device).

Querying location sources

Location data can be retrieved from various location sources, such as an internal GPS receiver, an external GPS receiver, or a geolocation service. Before retrieving location data, you should verify which location sources the BlackBerry device supports, and whether the location source is available. A location source may be unsupported for the following reasons:

  • The location source is not supported by the device hardware.
  • The location source is turned off by the wireless service provider (no service book present).
  • If the mobile network connection is turned off, the location source for cell site geolocation is not supported but the location source for GPS is supported, however, the time to the first fix may be slow.
  • If the Wi-Fi connection is turned off, the location source for geolocation by using WLAN access points is not supported.
  • If there is insufficient network connectivity, the geolocation location source is not supported.

A location source is available if all the settings are turned on for the source. However, a location source may be supported but might be unavailable on the device (for example, the BlackBerry device user turned off the location source).

The location sources are defined as constants in the GPSInfo and LocationInfo classes. The constants can be one of the following values:

  • GPSInfo.GPS_DEVICE_INTERNAL
  • GPSInfo.GPS_DEVICE_BLUETOOTH
  • LocationInfo.LOCATION_SOURCE_GEOLOCATION
  • LocationInfo.LOCATION_SOURCE_GEOLOCATION_CELL
  • LocationInfo.LOCATION_SOURCE_GEOLOCATION_WLAN

You can query location sources by using the following methods that are defined in the net.rim.device.api.gps.LocationInfo class:

Method

Description

getSupportedLocationSources()

This method returns an integer mask that represents the location sources that the device supports.

isLocationSourceSupported(int mode)

This method returns a value of true if the source you specify is supported on the device.

getAvailableLocationSources()

This method returns an integer mask that represents the location sources that the device supports. A location source is available if it is supported and enabled for use.

isLocationSourceAvailable(int mode)

This method returns a value of true if the mode you specify is available to provide location information.

The following code snippet verifies whether location sources are supported.

int locationCapability = LocationInfo
        .getSupportedLocationSources();
boolean gps = (locationCapability & (GPSInfo.GPS_DEVICE_INTERNAL | 
        GPSInfo.GPS_DEVICE_BLUETOOTH)) != 0

The following code snippet verifies whether any location sources are available.

if (LocationInfo.getAvailableLocationSources() != 0)