BlackBerry Location APIs - Part 2: Retrieve Location Fixes

Page content

BlackBerry: Retrieve Location Fixes

This article is the second part of a series of articles dealing with location APIs.

We will start where we left off in the previous article, talking about how to retrieve the location fixes. You can retrieve fixes in two ways: single fix or multiple fix.

3. Retrieve Location fixes

Single Fix:

Location LocationProvider.getLocation(int timeout);

Where timeout value specifies the maximum time to get the fix. You can set it to -1 to set it as default.

Multiple Fix:

This method is used to get multiple fixes at certain intervals. We need to implement a LocationListener which will receive the fixes every time the location changes.

In our LocationListener implementation we have to specifically implement the LocationUpdated method.

public void locationUpdated(LocationProvider provider, Location location)

After that, we just have to set this listener to our LocationProvider or BlackBerryLocationProvider:

LocationProvider.setLocationListener(LocationListener, interval, timeout, maxAge)

BlackBerryLocationProvider.setLocationListener(LocationListener, interval, timeout, maxAge)

The code

Let’s explain now what information has a location object and how to get it.

Location Object

  • Location.getLocationMethod()
    • Returns an integer mask of MTA_*, MTE_* and MTY_* constants in the Location class.
    • Represents the GPS mode used to compute this Location.
  • Location.getQualifiedCoordinates()
    • Returns a QualifiedCoordinate object from which longitude, latitude and altitude information can be extracted.
  • Location.getSpeed()
    • Returns the current ground speed in meters/second at the time of measurement.
  • Location.getCourse()
    • Returns the course made good in degrees relative to true north.
  • Location.getTimeStamp()
    • Returns the timestamp at which the data was collected.
  • Location.isValid
    • Returns the validity of the Location object. A failed fix usually results in an invalid fix.
  • Location.getExtraInfo(application/X-jsr179-location-nmea)
    • The raw location information in nmea format.
    • Number of satellites can be parsed from this.

BlackBerry Location Object

This object has more information than a simple Location object but it’s only available with BB 5.0 OS and above. Some of the new methods are the following:

  • BlackBerryLocation.getAverageSatelliteSignalQuality()
    • Returns the average satellite signal strength.
    • A good GPS fix ideally requires 4 or 5 satellites with good signal strength. Although the average signal strength gives us an idea about how good the GPS coverage is, it is important to ensure that the individual signal strength between the device and each satellite is good enough. More on this in the Best Practices section below.
  • BlackBerryLocation.getDataSource()
    • Returns the data source used to produce the location fix.
    • One of
      • LocationInfo.LOCATION_SOURCE_GEOLOCATION (since OS 6.0)
      • LocationInfo.LOCATION_SOURCE_GEOLOCATION_CELL (since OS 6.0)
      • LocationInfo.LOCATION_SOURCE_GEOLOCATION_WLAN (since OS 6.0)
  • BlackBerryLocation.getGPSMode()
    • Returns the GPS mode used to compute the location fix.
    • See GPSInfo.GPS_MODE_* and LocationInfo.GEOLOCATION_MODE constants.
  • BlackBerryLocation.getSatelliteCount()
    • Returns the number of satellites used to compute this fix.
  • BlackBerryLocation.getSatelliteInfo()
    • Returns an Enumeration of SatelliteInfo objects each representing a satellite that was in sight while computing this location.
    • SatelliteInfo contains azimuth, elevation, ID, signal quality and validity.
  • BlackBerryLocation.getError()
    • Returns the error code (if any) of this location.
    • Error codes are defined in GPSInfo class.
    • More on error codes later in this series.
  • BlackBerryLocation.getStatus()
    • Returns the status of a location fix.
    • More on status later in this series.