Android Programming Press on the image to return to the main documentation page.

FusedLocationProvider

Written by Martin Pearman

The FusedLocationProvider intelligently manages the underlying location technology and gives you the best location according to your needs.
https://developer.android.com/google/play-services/location.html
This library depends on the Google Play Services library, android-support-v4 library and the GPS library.
The GPS library is required in order to use it's Location object.

List of types:

ConnectionResult
FusedLocationProvider
LocationRequest
LocationSettingsRequestBuilder
LocationSettingsResult
LocationSettingsStates
LocationSettingsStatus
Priority
StatusCodes
SuspendedCause

ConnectionResult


Events:

None

Members:


  API_UNAVAILABLE As Int

  CANCELLED As Int

  DEVELOPER_ERROR As Int

  INTERNAL_ERROR As Int

  INVALID_ACCOUNT As Int

  LICENSE_CHECK_FAILED As Int

  NETWORK_ERROR As Int

  RESOLUTION_REQUIRED As Int

  SERVICE_DISABLED As Int

  SERVICE_INVALID As Int

  SERVICE_MISSING As Int

  SERVICE_VERSION_UPDATE_REQUIRED As Int

  SIGN_IN_REQUIRED As Int

  SUCCESS As Int

Members description:

API_UNAVAILABLE As Int
One of the API components you attempted to connect to is not available.
CANCELLED As Int
The client cancelled the connection by calling Disconnect().
DEVELOPER_ERROR As Int
The application is misconfigured.
INTERNAL_ERROR As Int
An internal error occurred.
INVALID_ACCOUNT As Int
The client attempted to connect to the service with an invalid account name specified.
LICENSE_CHECK_FAILED As Int
The application is not licensed to the user. This error is not recoverable and will be treated as fatal.
NETWORK_ERROR As Int
A network error occurred. Retrying should resolve the problem.
RESOLUTION_REQUIRED As Int
Completing the connection requires some form of resolution.
SERVICE_DISABLED As Int
The installed version of Google Play services has been disabled on this device.
SERVICE_INVALID As Int
The version of the Google Play services installed on this device is not authentic.
SERVICE_MISSING As Int
Google Play services is missing on this device.
SERVICE_VERSION_UPDATE_REQUIRED As Int
The installed version of Google Play services is out of date.
SIGN_IN_REQUIRED As Int
The client attempted to connect to the service but the user is not signed in.
SUCCESS As Int
The connection was successful.

FusedLocationProvider


Events:

ConnectionFailed(ConnectionResult1 As Int)
ConnectionSuccess
ConnectionSuspended(SuspendedCause1 As Int)
LocationChanged(Location1 As Location)
LocationSettingsChecked(LocationSettingsResult1 As LocationSettingsResult)

Members:


  CheckLocationSettings (LocationSettingsRequest1 As com.google.android.gms.location.LocationSettingsRequest)

  Connect

  ConnectionResult As ConnectionResult

  Disconnect

  GetLastKnownLocation As LocationWrapper

  Initialize (EventName As String)

  IsConnected As Boolean

  IsConnecting As Boolean

  IsInitialized As Boolean

  RemoveLocationUpdates

  RequestLocationUpdates (LocationRequest1 As com.google.android.gms.location.LocationRequest)

  SuspendedCause As SuspendedCause

Members description:

CheckLocationSettings (LocationSettingsRequest1 As com.google.android.gms.location.LocationSettingsRequest)
Checks if the relevant system settings are enabled on the device to carry out the desired location requests.
Raises the event:
LocationSettingsChecked(LocationSettingsResult1 As LocationSettingsResult)
Connect
Attempt to connect to the Location Services.
Will raise either event:
ConnectionFailed(ConnectionResult1 As Int)
ConnectionSuccess
ConnectionResult As ConnectionResult
Contains the various ConnectionResult constants.
Disconnect
Disconnect from the Location Services.
GetLastKnownLocation As LocationWrapper
Returns the best most recent location currently available.
Can only be called if the FusedLocationProvider is connected.
The returned Location object will not be initialized if no last known location is available.
Initialize (EventName As String)
Initialize the FusedLocationProvider object.
IsConnected As Boolean
Returns whether the FusedLocationProvider is connected to the Location Services.
IsConnecting As Boolean
Returns whether the FusedLocationProvider is trying to connect to the Location Services.
IsInitialized As Boolean
RemoveLocationUpdates
Remove all requests for location updates.
RequestLocationUpdates (LocationRequest1 As com.google.android.gms.location.LocationRequest)
Request for location updates.
The LocationRequest object defines the criteria for which location updates are requested.
SuspendedCause As SuspendedCause
Contains the various SuspendedCause constants.

LocationRequest


Events:

None

Members:


  GetExpirationTime As Long

  GetFastestInterval As Long

  GetInterval As Long

  GetNumUpdates As Int

  GetPriority As Int

  GetSmallestDisplacement As Float

  Initialize

  IsInitialized As Boolean

  Priority As Priority

  SetExpirationDuration (Millis As Long) As LocationRequest

  SetExpirationTime (Millis As Long) As LocationRequest

  SetFastestInterval (Millis As Long) As LocationRequest

  SetInterval (Millis As Long) As LocationRequest

  SetNumUpdates (NumUpdates As Int) As LocationRequest

  SetPriority (Priority As Int) As LocationRequest

  SetSmallestDisplacement (SmallestDisplacementMeters As Float) As LocationRequest

Members description:

GetExpirationTime As Long
Get the request expiration time, in milliseconds since boot.
GetFastestInterval As Long
Get the fastest interval of this request, in milliseconds.
GetInterval As Long
Get the desired interval of this request, in milliseconds.
GetNumUpdates As Int
Get the number of updates requested.
GetPriority As Int
Get the quality of the request.
GetSmallestDisplacement As Float
Get the minimum displacement between location updates in meters.
By default this is 0.
Initialize
Initialize the LocationRequest with default parameters.
Default parameters are for a block accuracy, slowly updated location.
IsInitialized As Boolean
Priority As Priority
Contains the various priority constants.
SetExpirationDuration (Millis As Long) As LocationRequest
Set the duration of this request, in milliseconds.
SetExpirationTime (Millis As Long) As LocationRequest
Set the request expiration time, in millisecond since boot.
SetFastestInterval (Millis As Long) As LocationRequest
Explicitly set the fastest interval for location updates, in milliseconds.
SetInterval (Millis As Long) As LocationRequest
Set the desired interval for active location updates, in milliseconds.
SetNumUpdates (NumUpdates As Int) As LocationRequest
Set the number of location updates.
SetPriority (Priority As Int) As LocationRequest
Set the priority of the request.
SetSmallestDisplacement (SmallestDisplacementMeters As Float) As LocationRequest
Set the minimum displacement between location updates in meters.
By default this is 0.

LocationSettingsRequestBuilder


Events:

None

Members:


  AddLocationRequest (LocationRequest1 As com.google.android.gms.location.LocationRequest) As LocationSettingsRequestBuilder

  Build As com.google.android.gms.location.LocationSettingsRequest

  Initialize

  IsInitialized As Boolean

  SetAlwaysShow (AlwaysShow As Boolean) As LocationSettingsRequestBuilder

  SetNeedBle (NeedBle As Boolean) As LocationSettingsRequestBuilder

Members description:

AddLocationRequest (LocationRequest1 As com.google.android.gms.location.LocationRequest) As LocationSettingsRequestBuilder
Adds one LocationRequest that the client is interested in.
This method can be called multiple times if required to add additional location requests.
Build As com.google.android.gms.location.LocationSettingsRequest
Creates a LocationSettingsRequest.
Initialize
IsInitialized As Boolean
SetAlwaysShow (AlwaysShow As Boolean) As LocationSettingsRequestBuilder
Always show the dialog, without the "Never" option to suppress future dialogs from this app.
When this flag is set to true, the dialog will show up if the location settings do not satisfy the request, even if a user has previously chosen "Never".
NOTE: Only use this method if your dialog is the result of an explicit user-initiated action that requires location to proceed.
Cancelling this dialog should also cancel the initiated action.
SetNeedBle (NeedBle As Boolean) As LocationSettingsRequestBuilder
Sets whether the client wants BLE scan to be enabled.
When this flag is set to true, if the platform supports BLE scan mode and Bluetooth is off, the dialog will prompt the user to enable BLE scan.
If the platform doesn't support BLE scan mode, the dialog will prompt to enable Bluetooth.

LocationSettingsResult


Events:

None

Members:


  GetLocationSettingsStates As LocationSettingsStates

  GetLocationSettingsStatus As LocationSettingsStatus

  IsInitialized As Boolean

Members description:

GetLocationSettingsStates As LocationSettingsStates
Returns the location settings states.
GetLocationSettingsStatus As LocationSettingsStatus
Returns the location settings result status.
IsInitialized As Boolean

LocationSettingsStates


Events:

None

Members:


  IsBlePresent As Boolean

  IsBleusable As Boolean

  IsGpsPresent As Boolean

  IsGpsUsable As Boolean

  IsInitialized As Boolean

  IsLocationPresent As Boolean

  IsLocationUsable As Boolean

  IsNetworkLocationPresent As Boolean

  IsNetworkLocationUsable As Boolean

Members description:

IsBlePresent As Boolean
Whether BLE is present on the device.
IsBleusable As Boolean
Whether BLE is enabled and is usable by the app.
IsGpsPresent As Boolean
Whether GPS provider is present on the device.
IsGpsUsable As Boolean
Whether GPS provider is enabled and is usable by the app.
IsInitialized As Boolean
IsLocationPresent As Boolean
Whether location is present on the device.
This method returns true when either GPS or network location provider is present.
IsLocationUsable As Boolean
Whether location is enabled and is usable by the app.
This method returns true when either GPS or network location provider is usable.
IsNetworkLocationPresent As Boolean
Whether network location provider is present on the device.
IsNetworkLocationUsable As Boolean
Whether network location provider is enabled and usable by the app.

LocationSettingsStatus


This is an 'Activity Object', it cannot be declared under Sub Process_Globals.

Events:

ResolutionDialogDismissed(LocationSettingsUpdated As Boolean)

Members:


  GetStatusCode As Int

  IsInitialized As Boolean

  StartResolutionDialog (EventName As String)

  StatusCodes As StatusCodes

Members description:

GetStatusCode As Int
Returns the status code that describes whether the location settings meet the location request requirements.
IsInitialized As Boolean
StartResolutionDialog (EventName As String)
Starts the resolution dialog.
The user can then enable the location settings required to meet the location request requirements.
This method must be called from an Activity.
Raises the event:
ResolutionDialogDismissed(LocationSettingsUpdated As Boolean)
StatusCodes As StatusCodes
Contains the various StatusCode constants.

Priority


Events:

None

Members:


  PRIORITY_BALANCED_POWER_ACCURACY As Int

  PRIORITY_HIGH_ACCURACY As Int

  PRIORITY_LOW_POWER As Int

  PRIORITY_NO_POWER As Int

Members description:

PRIORITY_BALANCED_POWER_ACCURACY As Int
Used with SetPriority(Int) to request "block" level accuracy.
PRIORITY_HIGH_ACCURACY As Int
Used with SetPriority(Int) to request the most accurate locations available.
PRIORITY_LOW_POWER As Int
Used with SetPriority(Int) to request "city" level accuracy.
PRIORITY_NO_POWER As Int
Used with SetPriority(Int) to request the best accuracy possible with zero additional power consumption.

StatusCodes


Events:

None

Members:


  RESOLUTION_REQUIRED As Int

  SETTINGS_CHANGE_UNAVAILABLE As Int

  SUCCESS As Int

Members description:

RESOLUTION_REQUIRED As Int
Location settings do not meet the location request requirements.
Location settings can be changed to meet the location request requirements.
A resolution dialog is available.
SETTINGS_CHANGE_UNAVAILABLE As Int
Location settings do not meet the location request requirements.
Location settings can't be changed to meet the location request requirements.
No resolution dialog is available.
SUCCESS As Int
Location settings meet the location request requirements.

SuspendedCause


Events:

None

Members:


  CAUSE_NETWORK_LOST As Int

  CAUSE_SERVICE_DISCONNECTED As Int

Members description:

CAUSE_NETWORK_LOST As Int
A connection suspended cause informing you that a peer device connection was lost.
CAUSE_SERVICE_DISCONNECTED As Int
A connection suspended cause informing that the service has been killed.
Top