【发布时间】:2020-07-21 10:53:01
【问题描述】:
在使用 FucedLocationProviderClient 之前,我需要先连接 GoogleApiClient 吗?
【问题讨论】:
标签: android google-api location
在使用 FucedLocationProviderClient 之前,我需要先连接 GoogleApiClient 吗?
【问题讨论】:
标签: android google-api location
不。您不需要 GoogleApiClient。 FusedLocationProviderClient 将在没有 GoogleApiClient 的情况下工作。
使用 FusedLocationProviderClient 获取位置的示例代码。
private FusedLocationProviderClient mFusedLocationClient;
//Intialize
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
//After get it the permission and GPS ON - write this below code
fusedLocationClient.getLastLocation()
.addOnSuccessListener(this, new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
// Got last known location. In some rare situations this can be null.
if (location != null) {
//handle location
}
}
});
【讨论】: