Java Reference
In-Depth Information
API implementation to notify your application if the source of location data has
changed (perhaps as a result of transitioning from one network to another). You use
the LocationListener interface any time you want to receive continuous position notifi-
cations, such as an application that provides real-time position reports as the device
moves. The ProximityListener interface lets your application wait for notification when
the terminal has fallen within the proximity radius around a specific coordinate. Using
the ProximityListener to determine when the device reaches a predetermined location
is more efficient than using the LocationListener , because the underlying implementa-
tion of the positioning hardware may have similar capabilities. It's also easier; you don't
need to receive and manage regular position reports just to determine if the device has
reached a desired location.
The LocationException and LandmarkException are exceptions the implementation
may throw in response to critical failures of either the location subsystem or the land-
mark store. For both exceptions, the String associated with the exception gives additional
information about the details surrounding the failure.
You can do two things with the Location API: determine the device's location, and
manage the landmarks the user has created for LBS applications to use.
Using the Location API to Determine Device Location
Using the Location API requires that you perform three steps:
1. Establish the (possibly user-specified) criteria for the location request.
2. Obtain a LocationProvider instance that can provide your application with the
device's location in a manner that meets your criteria.
3. Determine the position's location.
The pseudocode in Listing 17-1 shows this basic sequence of events.
Listing 17-1. Determining the Device Location
try {
Criteria cr = new Criteria();
cr.setHorizontalAccuracy(10);
LocationProvider lp = LocationProvider.getInstance(cr);
Location l = lp.getLocation(60);
Coordinates c = l.getQualifiedCoordinates();
if (c != null) {
// Do something with the location
}
} catch (LocationException e) {}
catch (Exception e) {}
 
Search WWH ::




Custom Search