Development Guide

Local Navigation

Querying location sources

Location data can be retrieved by using 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 might 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.

Code sample: Verifying whether location sources are supported

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

Code sample: Verifying whether any location sources are available

if (LocationInfo.getAvailableLocationSources() != 0)

Was this information helpful? Send us your comments.