智能客服
你问我答,随时在线为你解决问题
| Class Info |
|---|
| public class FusedLocationProviderClient 融合定位,程序定位交互接入类。在调用LocationServices类的getFusedLocationProviderClient(Activity activity)方法时会返回一个该类型的实例。 |
- private FusedLocationProviderClient fusedLocationProviderClient;
- fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
- private lateinit var mFusedLocationProviderClient: FusedLocationProviderClient
- mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this)
| Qualifier and Type | Field and Description |
|---|---|
| static final String | Location对象中的mExtras字段,包含一组键值对,其中键是KEY_MOCK_LOCATION,值为布尔值。通过该字段可以判断当前Location对象是否是模拟位置。 |
| static final String | KEY_VERTICAL_ACCURACY 预留字段,暂时不支持该能力。 |
| Qualifier and Type | Method Name and Description |
|---|---|
| Task<Void> | 移除后台服务。 说明 Location kit 6.0.0版本新增方法,仅HMS Core非预装场景时支持使用,用于部分厂商或机型在持续定位的过程中,应用进入后台或者息屏场景下,因系统省电策略导致停止位置回调,开启后台定位后,该场景下仍能持续提供定位能力。 |
| Task<Void> | enableBackgroundLocation(int id, Notification notification) 开启后台服务。 说明 Location kit 6.0.0版本新增方法,仅HMS Core非预装场景时支持使用,用于部分厂商或机型在持续定位的过程中,应用进入后台或者息屏场景下,因系统省电策略导致停止位置回调,开启后台定位后,该场景下仍能持续提供定位能力。 |
| Task<Void> | 刷新当前正在处理的位置。 |
| Task<Location> | 返回最后一次请求的可用位置。 |
| getLastLocationWithAddress(LocationRequest request) 返回最后一次请求的可用位置,包括详细地址信息。如果某个位置不可用,则返回null。 | |
| 返回位置数据的可用性。 | |
| Task<Void> | removeLocationUpdates(LocationCallback callback) 移除指定回调信息的位置更新。针对同一个callback重复请求时,不需要调用此方法做移除操作。 |
| Task<Void> | removeLocationUpdates(PendingIntent callbackIntent) 移除指定PendingIntent的位置更新。 注意 1.非华为手机暂不支持此功能。 |
| Task<Void> | requestLocationUpdates(LocationRequest request, LocationCallback callback, Looper looper) 请求位置更新,并在指定的Looper线程上回调。 |
| Task<Void> | requestLocationUpdates(LocationRequest request, PendingIntent callbackIntent) 请求方使用PendingIntent的方式,持续请求位置更新。 注意 1.非华为手机暂不支持此功能。 |
| Task<Void> | requestLocationUpdatesEx(LocationRequest request, LocationCallback callback, Looper looper) 扩展的位置信息服务接口,当前支持室外高精度和室内定位,并兼容普通定位接口。 注意
|
| Task<Void> | setMockLocation(Location mockLocation) 设置具体的模拟位置。 |
| Task<Void> | setMockMode(boolean isMockMode) 设置位置提供者是否使用位置模拟模式。 |
| Fields |
|---|
| public static final String KEY_MOCK_LOCATION Location对象中的mExtras字段,包含一组键值对,其中键是KEY_MOCK_LOCATION,值为布尔值。通过该字段可以判断当前Location对象是否是模拟位置。 使用方式:location.getExtras().getBoolean(FusedLocationProviderClient.KEY_MOCK_LOCATION)。 KEY_MOCK_LOCATION:“mockLocation”,其余常量值请参阅:Constant-values。 |
Location kit 6.0.0版本新增方法,仅HMS Core非预装场景时支持使用,用于部分厂商或机型在持续定位的过程中,应用进入后台或者息屏场景下,因系统省电策略导致停止位置回调,开启后台定位后,该场景下仍能持续提供定位能力。
| Method |
|---|
| public Task<Void> disableBackgroundLocation() 移除后台服务。 |
Returns
| Type | Description |
|---|---|
| Task<Void> | 任务。通过addOnSuccessListener()和addOnFailureListener()添加监听,然后通过onSuccess()和onFailure()方法获取任务执行结果。 |
Location kit 6.0.0版本新增方法,仅HMS Core非预装场景时支持使用,用于部分厂商或机型在持续定位的过程中,应用进入后台或者息屏场景下,因系统省电策略导致停止位置回调,开启后台定位后,该场景下仍能持续提供定位能力。
| Method |
|---|
| public Task<Void> enableBackgroundLocation(int id, Notification notification) 开启后台服务。 |
Parameters
| Name | Description |
|---|---|
| id | 通知id,此id不能为0。 |
| notification | 通知。 |
Returns
| Type | Description |
|---|---|
| Task<Void> | 任务。通过addOnSuccessListener()和addOnFailureListener()添加监听,然后通过onSuccess()和onFailure()方法获取任务执行结果。 |
| Method |
|---|
| public Task<Void> flushLocations() 刷新当前正在处理的位置。 |
Returns
| Type | Description |
|---|---|
| Task<Void> | 任务。通过addOnSuccessListener()和addOnFailureListener()添加监听,然后通过onSuccess()和onFailure()方法获取任务执行结果。 |
当前版本并未提供flushLocations()功能,SDK中为空实现。
| Method |
|---|
| public Task<Location> getLastLocation() 返回最后一次请求的可用位置。该接口并不会主动请求位置,将使用上一次请求的缓存位置。 以下场景可能导致返回null:
如果对位置的实时性有较高要求,推荐主动调用requestLocationUpdates替代调用getLastLocation。如果只想收到一次位置信息,可以将LocationRequest中numUpdates参数设置为1。 |
Returns
| Type | Description |
|---|---|
| Task<Location> | 任务。通过addOnSuccessListener()和addOnFailureListener()添加监听,然后通过onSuccess()和onFailure()方法获取任务执行结果。 |
| Method |
|---|
| public Task<HWLocation> getLastLocationWithAddress(LocationRequest request) 返回最后一次请求的可用位置,包括详细地址信息。如果某个位置不可用,则返回null。 |
Parameters
| Name | Description |
|---|---|
| request | 位置请求对象。 |
Returns
| Type | Description |
|---|---|
| 任务。通过addOnSuccessListener()和addOnFailureListener()添加监听,然后通过onSuccess()和onFailure()方法获取任务执行结果。 |
| Method |
|---|
| public Task<LocationAvailability> getLocationAvailability() 返回位置数据的可用性。 |
Returns
| Type | Description |
|---|---|
| 任务。通过添加addOnSuccessListener()和addOnFailureListener()监听,然后通过onSuccess()和onFailure()方法获取任务执行结果。 失败的情况下,需要将抛出的Exception对象强转为ApiException对象,再调用ApiException对象的getStatusCode()方法确定返回码:
|
| Method |
|---|
| public Task<Void> removeLocationUpdates(LocationCallback callback) 移除指定回调信息的位置更新。针对同一个callback重复请求时,不需要调用此方法做移除操作。 |
Parameters
| Name | Description |
|---|---|
| callback | 要移除的回调信息。 |
Returns
| Type | Description |
|---|---|
| Task<Void> | 任务。通过addOnSuccessListener()和addOnFailureListener()添加监听,然后通过onSuccess()和onFailure()方法获取任务执行结果。 |
| Method |
|---|
| public Task<Void> removeLocationUpdates(PendingIntent callbackIntent) 移除指定PendingIntent的位置更新。 |
Parameters
| Name | Description |
|---|---|
| callbackIntent | 要移除的PendingIntent对象。 |
Returns
| Type | Description |
|---|---|
| Task<Void> | 任务。通过addOnSuccessListener()和addOnFailureListener()添加监听,然后通过onSuccess()和onFailure()方法获取任务执行结果。 |
| Method |
|---|
| public Task<Void> requestLocationUpdates(LocationRequest request,LocationCallback callback,Looper looper) 请求位置更新,并在指定的Looper线程上回调。该方法要求请求方进程存在才能持续回调。如进程终止后仍然希望能够持续收到回调,请参见requestLocationUpdates(LocationRequest request,PendingIntent callbackIntent)。 此接口请求成功的结果是在Task的addOnSuccessListener()的onSuccess()中,位置回调的结果是在LocationCallback的onLocationResult()中,这两种回调是并发任务,无法保证onSuccess()和onLocationResult()回调时序。 |
Parameters
| Name | Description |
|---|---|
| request | 位置请求对象。 |
| callback | 位置更新的回调。 |
| looper | 指定线程的looper对象。 说明 6.4.0.300及以后版本不支持looper为null。 |
Returns
| Type | Description |
|---|---|
| Task<Void> | 任务。通过addOnSuccessListener()和addOnFailureListener()添加监听,然后通过onSuccess()和onFailure()方法获取任务执行结果。 |
| Method |
|---|
| public Task<Void> requestLocationUpdates(LocationRequest request,PendingIntent callbackIntent) 请求方使用PendingIntent的方式,持续请求位置更新,HMS Core把位置更新的结果LocationResult和LocationAvailability封装到Intent中,调用传入的PendingIntent的send()发送给请求方。如果请求方进程终止,使用此方法,依然能够持续回调。 此接口请求成功的结果是在Task的addOnSuccessListener()的onSuccess()中,位置回调的结果是在PendingIntent对应的广播接收器中接收的,这两种回调是并发任务,无法保证onSuccess()和广播接收器收到位置回调的时序。 |
Parameters
| Name | Description |
|---|---|
| request | 位置请求对象。 |
| callbackIntent | 每个位置请求更新关联的PendingIntent,构造PendingIntent时需设置Class、Action,不能构造空Intent。 |
Returns
| Type | Description |
|---|---|
| Task<Void> | 任务。通过addOnSuccessListener()和addOnFailureListener()添加监听,然后通过onSuccess()和onFailure()方法获取任务执行结果。 |
| Method |
|---|
| public Task<Void> requestLocationUpdatesEx(LocationRequest request,LocationCallback callback,Looper looper) 扩展的位置信息服务接口,当前支持室外高精度和室内定位,并兼容普通定位接口。
|
Parameters
| Name | Description |
|---|---|
| request | 位置请求对象。 |
| callback | 位置更新的回调。 |
| looper | 指定线程的looper对象。 说明 6.4.0.300及以后版本不支持looper为null。 |
Returns
| Type | Description |
|---|---|
| Task<Void> | 任务。通过addOnSuccessListener()和addOnFailureListener()添加监听,然后通过onSuccess()和onFailure()方法获取任务执行结果。 |
| Method |
|---|
| public Task<Void> setMockLocation(Location mockLocation) 设置具体的模拟位置。必须在调用此方法之前调用setMockMode(boolean)并设置为true。 |
Parameters
| Name | Description |
|---|---|
| mockLocation | 模拟位置。此类为Android原生类,具体介绍请参见Android开发文档。 |
Returns
| Type | Description |
|---|---|
| Task<Void> | 任务。通过addOnSuccessListener()和addOnFailureListener()添加监听,然后通过onSuccess()和onFailure()方法获取任务执行结果。 |
| Method |
|---|
| public Task<Void> setMockMode(boolean isMockMode) 设置位置提供者是否使用位置模拟模式。为true时,将不再使用GNSS或网络位置,最终直接返回通过setMockLocation(Location)设置的位置信息。 |
Parameters
| Name | Description |
|---|---|
| isMockMode | 如果为true,则位置提供者将设置为模拟模式。如果为false,它将返回到正常状态。 |
Returns
| Type | Description |
|---|---|
| Task<Void> | 任务。通过addOnSuccessListener()和addOnFailureListener()添加监听,然后通过onSuccess()和onFailure()方法获取任务执行结果。 |