Task
Steps
Specify a level of accuracy,
with no cost and variable
power consumption.
a.
Invoke
criteria.setHorizontalAccuracy(NO_REQUIREMENT)
.
b.
Invoke
criteria.setVerticalAccuracy(NO_REQUIREMENT)
.
c.
Invoke
criteria.setCostAllowed(false)
.
d.
Invoke
criteria.setPreferredPowerConsumption(int level)
using
one of
POWER_USAGE_MEDIUM
,
POWER_USAGE_HIGH
, or
NO_REQUIREMENT
as the parameter.
3.
Invoke
LocationProvider.getInstance()
, storing the returned object in a
LocationProvider
object.
LocationProvider provider = LocationProvider.getInstance(criteria);
Getting GPS location information
Specify a response time for getting the location of the BlackBerry device
Invoke
Criteria.setPreferredResponseTime()
, and specify the response time, in milliseconds.
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 BlackBerry device, in meters per second
Invoke
location.getSpeed()
.
Location location = provider.getLocation(-1);
float speed = mylocation.getSpeed();
Development Guide
Getting GPS location information
6