Android.Locations.LocationManager.RequestLocationUpdates Method
Register for location updates using a Criteria and pending intent.

Syntax

[Android.Runtime.Register("requestLocationUpdates", "(JFLandroid/location/Criteria;Landroid/app/PendingIntent;)V", "GetRequestLocationUpdates_JFLandroid_location_Criteria_Landroid_app_PendingIntent_Handler")]
public virtual void RequestLocationUpdates (long minTime, float minDistance, Criteria criteria, Android.App.PendingIntent intent)

Parameters

minTime
minimum time interval between location updates, in milliseconds
minDistance
minimum distance between location updates, in meters
criteria
contains parameters for the location manager to choose the appropriate provider and parameters to compute the location
intent
a Android.App.PendingIntent to be sent for each location update

Exceptions

TypeReason
Java.Lang.IllegalArgumentExceptionif criteria is null
Java.Lang.IllegalArgumentExceptionif intent is null
Java.Lang.SecurityExceptionif no suitable permission is present

Remarks

Register for location updates using a Criteria and pending intent.

The requestLocationUpdates() and requestSingleUpdate() register the current activity to be updated periodically by the named provider, or by the provider matching the specified Android.Locations.Criteria, with location and status updates.

It may take a while to receive the first location update. If an immediate location is required, applications may use the LocationManager.GetLastKnownLocation(string) method.

Location updates are received either by Android.Locations.ILocationListener callbacks, or by broadcast intents to a supplied Android.App.PendingIntent.

If the caller supplied a pending intent, then location updates are sent with a key of LocationManager.KeyLocationChanged and a Android.Locations.Location value.

The location update interval can be controlled using the minTime parameter. The elapsed time between location updates will never be less than minTime, although it can be more depending on the Location Provider implementation and the update interval requested by other applications.

Choosing a sensible value for minTime is important to conserve battery life. Each location update requires power from GPS, WIFI, Cell and other radios. Select a minTime value as high as possible while still providing a reasonable user experience. If your application is not in the foreground and showing location to the user then your application should avoid using an active provider (such as LocationManager.NetworkProvider or LocationManager.GpsProvider), but if you insist then select a minTime of 5 * 60 * 1000 (5 minutes) or greater. If your application is in the foreground and showing location to the user then it is appropriate to select a faster update interval.

The minDistance parameter can also be used to control the frequency of location updates. If it is greater than 0 then the location provider will only send your application an update when the location has changed by at least minDistance meters, AND at least minTime milliseconds have passed. However it is more difficult for location providers to save power using the minDistance parameter, so minTime should be the primary tool to conserving battery life.

If your application wants to passively observe location updates triggered by other applications, but not consume any additional power otherwise, then use the LocationManager.PassiveProvider This provider does not actively turn on or modify active location providers, so you do not need to be as careful about minTime and minDistance. However if your application performs heavy work on a location update (such as network activity) then you should select non-zero values for minTime and/or minDistance to rate-limit your update frequency in the case another application enables a location provider with extremely fast updates.

In case the provider is disabled by the user, updates will stop, and a provider availability update will be sent. As soon as the provider is enabled again, location updates will immediately resume and a provider availability update sent. Providers can also send status updates, at any time, with extra's specific to the provider. If a callback was supplied then status and availability updates are via ILocationListener.OnProviderDisabled(string), ILocationListener.OnProviderEnabled(string) or ILocationListener.OnStatusChanged(string, Android.Locations.Availability, Android.Locations.Availability). Alternately, if a pending intent was supplied then status and availability updates are broadcast intents with extra keys of LocationManager.KeyProviderEnabled or LocationManager.KeyStatusChanged.

If a Android.Locations.ILocationListener is used but with no Looper specified then the calling thread must already be a Android.OS.Looper thread such as the main thread of the calling Activity. If a Looper is specified with a Android.Locations.ILocationListener then callbacks are made on the supplied Looper thread.

Prior to Jellybean, the minTime parameter was only a hint, and some location provider implementations ignored it. From Jellybean and onwards it is mandatory for Android compatible devices to observe both the minTime and minDistance parameters.

[Android Documentation]

Requirements

Namespace: Android.Locations
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 9