- slide 1 of 2
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
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.
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)
- slide 2 of 2
Let’s explain now what information has a location object and how to get it.
- Returns an integer mask of MTA_*, MTE_* and MTY_* constants in the Location class.
- Represents the GPS mode used to compute this Location.
- Returns a QualifiedCoordinate object from which longitude, latitude and altitude information can be extracted.
- Returns the current ground speed in meters/second at the time of measurement.
- Returns the course made good in degrees relative to true north.
- Returns the timestamp at which the data was collected.
- Returns the validity of the Location object. A failed fix usually results in an invalid fix.
- 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:
- 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.
- 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)
- Returns the GPS mode used to compute the location fix.
- See GPSInfo.GPS_MODE_* and LocationInfo.GEOLOCATION_MODE constants.
- Returns the number of satellites used to compute this fix.
- 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.
- Returns the error code (if any) of this location.
- Error codes are defined in GPSInfo class.
- More on error codes later in this series.
- Returns the status of a location fix.
- More on status later in this series.