CLASS info
public class FusedLocationProviderClient
Fused location class, which is used for interaction during location.

Public Method Summary

Return typeMethod name
Task<Void>flushLocations()
Task<Location>getLastLocation()
Task<LocationAvailability>
getLocationAvailability()
Task<Void>removeLocationUpdates(LocationCallback callback)
Task<Void>removeLocationUpdates(PendingIntent callbackIntent)
Task<Void>requestLocationUpdates(LocationRequest request, LocationCallback callback, Looper looper)
Task<Void>requestLocationUpdates(LocationRequest request, PendingIntent callbackIntent)
Task<Void>setMockMode(boolean isMockMode)
Task<Void>setMockLocation(Location mockLocation)
Task<HWLocation>getLastLocationWithAddress(LocationRequest request)
Task<Void>requestLocationUpdatesEx (LocationRequest request, LocationCallback callback, Looper looper)

Public Methods

Method
public Task<Void> flushLocations()
This API is used to update locations being processed.

Return

typedesc
Task<Void>Task. The addOnSuccesslistener() and addOnFailureListener() methods are used to add a listener, and the onSuccess() and onFailure() methods are used to obtain the task execution result.
Note:
Currently, this function(flushLocations()) is not provided and the function implementation is empty in the SDK.
Method


public Task<Location> getLastLocation()

This API is used to obtain the last requested available location.  This API does not proactively request the location. Instead, it uses the location cached for the last request.

This API may return null in the following scenarios:

  • The location function has never been used.

  • The location function is disabled.

  • The device is restored to factory settings.

If real-time location is required, you are advised to proactively call requestLocationUpdates instead of getLastLocation. To receive a location once only, you can set numUpdates in LocationRequest to 1.

Return

typedesc
Task<Location>Task. The addOnSuccesslistener() and addOnFailureListener() methods are used to add a listener, and the onSuccess() and onFailure() methods are used to obtain the task execution result.
Method
public Task<LocationAvailability> getLocationAvailability()
This API is used to check whether the location data is available. 

Return

typedesc
Task<LocationAvailability>Task. You can add addOnSuccesslistener() and addOnFailureListener() to obtain the execution result of the current method, and add getStateCode() to check whether the execution is successful. (0: success; 1: failure; 404: no resource; 500: internal error).
Method
public Task<Void> removeLocationUpdates(LocationCallback callback)
This API is used to remove location updates of the specified callback information.

Parameters

Parameter nameParameter desc
callbackCallback information to be removed.

Return

typedesc
Task<Void>Task. The addOnSuccesslistener() and addOnFailureListener() methods are used to add a listener, and the onSuccess() and onFailure() methods are used to obtain the task execution result.
Method
public Task<Void> removeLocationUpdates(PendingIntent callbackIntent)
This API is used to remove location updates from the specified PendingIntent object.

Parameters

Parameter nameParameter desc
callbackIntentPendingIntent object to be removed.

Return

typedesc
Task<Void>Task. The addOnSuccesslistener() and addOnFailureListener() methods are used to add a listener, and the onSuccess() and onFailure() methods are used to obtain the task execution result.
Method
public Task<Void> requestLocationUpdates(LocationRequest request,LocationCallback callback,Looper looper)
This API is used to request location updates using the callback on the specified Looper thread. This method can be called back continuously only when the request party’s process exists. To continuously receive callback after the request party’s process is stopped, use requestLocationUpdates(LocationRequest request,PendingIntent callbackIntent). If the API is called successfully but the location fails to be obtained, please refer to question 3 in FAQs.

Parameters

Parameter nameParameter desc
requestLocation update request.
callbackLocation update callback.
looperLooper object. If this parameter is left empty, the looper object of the current thread is used by default.

Return

typedesc
Task<Void>Task. The addOnSuccesslistener() and addOnFailureListener() methods are used to add a listener, and the onSuccess() and onFailure() methods are used to obtain the task execution result.
Method
public Task<Void> requestLocationUpdates(LocationRequest request,PendingIntent callbackIntent)
This API is used to continuously request location updates using PendingIntent. The HMS encapsulates LocationResult (containing the location update result) and LocationAvailability in Intent, which is sent to the request party by calling the send() method of the transferred PendingIntent. If the request party’s process is stopped, this method can be used for continuous callback.  If the API is called successfully but the location fails to be obtained, please refer to question 3 in FAQs.

Parameters

Parameter nameParameter desc
requestLocation update request.
callbackIntent

PendingIntent associated with each location update request. When building a pendingIntent object, you need to set class and action. Do not build an empty Intent object.

Return

typedesc
Task<Void>Task. The addOnSuccesslistener() and addOnFailureListener() methods are used to add a listener, and the onSuccess() and onFailure() methods are used to obtain the task execution result.
Method
public Task<Void> setMockMode(boolean isMockMode)
This API is used to specify whether the location provider uses the location mock mode. If yes, the GPS or network location is not used and the location set through setMockLocation (Location) is directly returned.

Parameters

Parameter nameParameter desc
isMockModeIf this parameter is set to true, the location provider is set to the mock mode. If this parameter is set to false, the location provider program returns to the normal mode.

Return

typedesc
Task<Void>Task. The addOnSuccesslistener() and addOnFailureListener() methods are used to add a listener, and the onSuccess() and onFailure() methods are used to obtain the task execution result.
Method
public Task<Void> setMockLocation(Location mockLocation)
This API is used to set the specific mock location. You must call the setMockMode(boolean) method and set the flag to true before calling this method.

Parameters

Parameter nameParameter desc
mockLocationMock location. This class is native to Android,For details,  please refer to the Android development documentation.

Return

typedesc
Task<Void>Task. The addOnSuccesslistener() and addOnFailureListener() methods are used to add a listener, and the onSuccess() and onFailure() methods are used to obtain the task execution result.
Method

public Task<HWLocation> getLastLocationWithAddress(LocationRequest request)

This API is used to obtain the available location of the last request, including the detailed address information. If a location is unavailable, null is returned.

Parameters

Parameter nameParameter desc
requestLocation Request Object.

Return

typedesc

Task<HWLocation>

Task. You can add listeners using addOnSuccesslistener() and addOnFailureListener(), and obtain the task execution result using onSuccess() and onFailure().

Method
public Task<Void> requestLocationUpdatesEx(LocationRequest request,LocationCallback callback,Looper looper)

This API is an extended location information service API. It supports high-precision location and is compatible with common location APIs. If the device does not support high-precision location or the app does not request the high-precision location permission, this API returns common location information similar to that returned by the requestLocationUpdates API. In the returned Location object, you can use getExtras().getInt("SourceType", 0) to obtain SourceType of the location information. If the last but three digits in the binary value of SourceType is 1, the location is a high-precision location. If the API is called successfully but the location fails to be obtained, please refer to question 3 in FAQs.


Parameters

Parameter nameParameter desc
request

Location request object. To obtain high-precision location information, you must set priority to 200.

callback

Location update callback.

looper

Looper object. If this parameter is left empty, the looper object of the current thread is used by default.

Return

typedesc
Task<Void>

Task. You can add listeners using addOnSuccesslistener() and addOnFailureListener(), and obtain the task execution result using onSuccess() and onFailure().