
13
2: Using GPS
Get the location information for a
BlackBerry device.
> In a non-event thread, invoke LocationProvider.getLocation(int), providing a
timeout, in seconds.
try {
// Specify -1 to have the implementation use its default timeout value
// for this provider.
Location location = provider.getLocation(-1);
} catch (Exception e) {
// handle LocationException, InterruptedException, SecurityException
// and IllegalArgumentException
}
Get the speed of the terminal, in meters
per second.
>Invoke location.getSpeed().
float speed = location.getSpeed();
Get the course of the terminal, in
degrees.
>Invoke location.getCourse().
float course = location.getCourse();
Get the number of GPS satellites that a
BlackBerry device tracks.
1. Invoke the Location.getExtraInfo() method using the National Marine Electronics
Association (NMEA) MIME type as a parameter. The method returns an encoded
String that
contains information on the number of GPS satellites.
String encodedStr = Location.getExtraInfo("application/X-jsr179-
location-nmea");
2. To retrieve the GPS satellite information, parse through the information in the returned
String value.
See the API reference for the BlackBerry® Java® Development Environment for more information
about the
Location.getExtraInfo() method.
Get the time that a BlackBerry device
application retrieved GPS information.
>Invoke Location.getTimeStamp(). The time is retrieved from the GPS receiver.
Location.getTimeStamp();
Maintain a connection with GPS
satellites.
Configure a BlackBerry device application to query the Location API for GPS location information
in an interval less than 10 seconds.
>Define a LocationListener with an interval value that is less than 10 seconds.
LocationProvider provider = LocationProvider.getInstance(criteria);
provider.setLocationListener(loclistener, 9, -1, -1);
Get continuous GPS readings using the
cell site mode.
>Use the LocationProvider.getLocation() method with a timer to simulate the
retrieval of GPS information at fixed intervals.
Get GPS information during a phone call. > Use the autonomous mode to retrieve GPS information. See “Get location information from the
GPS receiver on a BlackBerry device” on page 11 for more information.
Get location position updates. You can associate only one LocationListener with a particular location provider for GPS
location information. BlackBerry Java Applications typically listen for updates on a separate
thread.
1. Implement the LocationListener interface.
2. To register your implementation, invoke LocationProvider.setLocationListener().
Task Steps
Commenti su questo manuale