|
Build 1.0_r1 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectandroid.location.LocationManager
public class LocationManager
This class provides access to the system location services. These services allow applications to obtain periodic updates of the device's geographical location, or to fire an application-specified Intent when the device enters the proximity of a given geographical location.
You do not instantiate this class directly; instead, retrieve it through Context.getSystemService(Context.LOCATION_SERVICE).
| Field Summary | |
|---|---|
static String |
GPS_PROVIDER
Name of the GPS location provider. |
static String |
KEY_PROXIMITY_ENTERING
Key used for the Bundle extra holding a boolean indicating whether a proximity alert is entering (true) or exiting (false).. |
static String |
NETWORK_PROVIDER
Name of the network location provider. |
| Method Summary | |
|---|---|
void |
addProximityAlert(double latitude,
double longitude,
float radius,
long expiration,
PendingIntent intent)
|
List |
getAllProviders()
Returns a list of the names of all known location providers. |
String |
getBestProvider(Criteria criteria,
boolean enabledOnly)
Returns the name of the provider that best meets the given criteria. |
Location |
getLastKnownLocation(String provider)
Returns a Location indicating the data from the last known location fix obtained from the given provider. |
LocationProvider |
getProvider(String name)
Returns the information associated with the location provider of the given name, or null if no provider exists by that name. |
List |
getProviders(boolean enabledOnly)
Returns a list of the names of location providers. |
List |
getProviders(Criteria criteria,
boolean enabledOnly)
Returns a list of the names of LocationProviders that satisfy the given criteria, or null if none do. |
boolean |
isProviderEnabled(String provider)
Returns the current enabled/disabled status of the given provider. |
void |
removeProximityAlert(PendingIntent intent)
Removes the proximity alert with the given PendingIntent. |
void |
removeUpdates(LocationListener listener)
Removes any current registration for location updates of the current activity with the given LocationListener. |
void |
requestLocationUpdates(String provider,
long minTime,
float minDistance,
LocationListener listener)
Registers the current activity to be notified periodically by the named provider. |
void |
requestLocationUpdates(String provider,
long minTime,
float minDistance,
LocationListener listener,
Looper looper)
Registers the current activity to be notified periodically by the named provider. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String NETWORK_PROVIDER
public static final String GPS_PROVIDER
The extras Bundle for the GPS location provider can contain the following key/value pairs:
public static final String KEY_PROXIMITY_ENTERING
| Method Detail |
|---|
public List getAllProviders()
public List getProviders(boolean enabledOnly)
enabledOnly - if true then only the providers which are currently
enabled are returned.
public LocationProvider getProvider(String name)
name - the provider name
IllegalArgumentException - if name is null
SecurityException - if the caller is not permitted to access the
given provider.
public List getProviders(Criteria criteria,
boolean enabledOnly)
criteria - the criteria that the returned providers must matchenabledOnly - if true then only the providers which are currently
enabled are returned.
public String getBestProvider(Criteria criteria,
boolean enabledOnly)
Note that the requirement on monetary cost is not removed in this process.
criteria - the criteria that need to be matchedenabledOnly - if true then only a provider that is currently enabled is returned
public void requestLocationUpdates(String provider,
long minTime,
float minDistance,
LocationListener listener)
It may take a while to receive the most recent location. If an immediate location is required, applications may use the getLastKnownLocation(String) method.
In case the provider is disabled by the user, updates will stop, and the onProviderDisabled(String) method will be called. As soon as the provider is enabled again, the onProviderEnabled(String) method will be called and location updates will start again.
The frequency of notification may be controlled using the minTime and minDistance parameters. If minTime is greater than 0, the LocationManager could potentially rest for minTime milliseconds between location updates to conserve power. If minDistance is greater than 0, a location will only be broadcasted if the device moves by minDistance meters. To obtain notifications as frequently as possible, set both parameters to 0.
Background services should be careful about setting a sufficiently high minTime so that the device doesn't consume too much power by keeping the GPS or wireless radios on all the time. In particular, values under 60000ms are not recommended.
The calling thread must be a Looper thread such as the main thread of the calling Activity.
provider - the name of the provider with which to registerminTime - the minimum time interval for notifications, in
milliseconds. This field is only used as a hint to conserve power, and actual
time between location updates may be greater or lesser than this value.minDistance - the minimum distance interval for notifications,
in meterslistener - a {#link LocationListener} whose
onLocationChanged(Location) method will be called for
each location update
IllegalArgumentException - if provider is null or doesn't exist
IllegalArgumentException - if listener is null
RuntimeException - if the calling thread has no Looper
SecurityException - if no suitable permission is present for the provider.
public void requestLocationUpdates(String provider,
long minTime,
float minDistance,
LocationListener listener,
Looper looper)
It may take a while to receive the most recent location. If an immediate location is required, applications may use the getLastKnownLocation(String) method.
In case the provider is disabled by the user, updates will stop, and the onProviderDisabled(String) method will be called. As soon as the provider is enabled again, the onProviderEnabled(String) method will be called and location updates will start again.
The frequency of notification may be controlled using the minTime and minDistance parameters. If minTime is greater than 0, the LocationManager could potentially rest for minTime milliseconds between location updates to conserve power. If minDistance is greater than 0, a location will only be broadcasted if the device moves by minDistance meters. To obtain notifications as frequently as possible, set both parameters to 0.
Background services should be careful about setting a sufficiently high minTime so that the device doesn't consume too much power by keeping the GPS or wireless radios on all the time. In particular, values under 60000ms are not recommended.
The supplied Looper is used to implement the callback mechanism.
provider - the name of the provider with which to registerminTime - the minimum time interval for notifications, in
milliseconds. This field is only used as a hint to conserve power, and actual
time between location updates may be greater or lesser than this value.minDistance - the minimum distance interval for notifications,
in meterslistener - a {#link LocationListener} whose
onLocationChanged(Location) method will be called for
each location updatelooper - a Looper object whose message queue will be used to
implement the callback mechanism.
IllegalArgumentException - if provider is null or doesn't exist
IllegalArgumentException - if listener is null
IllegalArgumentException - if looper is null
SecurityException - if no suitable permission is present for the provider.public void removeUpdates(LocationListener listener)
listener - {#link LocationListener} object that no longer needs location updates
IllegalArgumentException - if listener is null
public void addProximityAlert(double latitude,
double longitude,
float radius,
long expiration,
PendingIntent intent)
public void removeProximityAlert(PendingIntent intent)
intent - the PendingIntent that no longer needs to be notified of
proximity alertspublic boolean isProviderEnabled(String provider)
provider - the name of the provider
SecurityException - if no suitable permission is present for the provider.
IllegalArgumentException - if provider is null or doesn't existpublic Location getLastKnownLocation(String provider)
If the provider is currently disabled, null is returned.
provider - the name of the provider
SecurityException - if no suitable permission is present for the provider.
IllegalArgumentException - if provider is null or doesn't exist
|
Build 1.0_r1 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||