Java Reference
In-Depth Information
the LocationProvider instance, you can determine either the current position or the last
known position (which may be null ) by invoking the LocationProvider 's getLocation or
getLastKnownLocation methods, respectively. Many of the LocationManager methods can
throw exceptions—typically LocationException s for location-based failures, or
SecurityException s if the user or platform does not permit the operation.
Tip Location determination can be a time-consuming process, and the LocationProvider implementa-
tion may block the current thread. For this reason, it's best to invoke getLocation in a thread separate from
the main thread, to avoid stalling the user interface of your application. I show you how to do this in a real
MIDlet later in this chapter, in the “Locating the User” section.
The specific Location instance that the LocationProvider class's getLocation method
returns provides the device's location at a specific instance in time that the implementa-
tion determined using a specific location method. When you invoke getLocation ,you
must pass a number indicating the maximum number of seconds your application is
willing to wait for the positioning request to complete.
From an instance of Location , you can use the following methods to determine more
about the device location:
isValid : Returns true if the Location is valid with coordinates
getQualifiedCoordinates : Returns the coordinates of the Location
getTimestamp : Returns when the location data was collected
getAddressInfo : Returns the street address (as an AddressInfo object)
getCourse : Returns the heading in degrees relative to true north
getSpeed : Returns the device's current ground speed in meters per second at the
measurement time
getLocationMethod : Returns a bit mask describing how the implementation
determined the location
getExtraInfo : Returns any additional information about the request
Table 17-2 describes the bit field values that the getLocationMethod uses to report how
the implementation determined the device's location.
 
Search WWH ::




Custom Search