我尝试使用 FusedLocationProviderClient
获取用户位置,如下所示:
fusedLocationProviderClient.requestLocationUpdates(mLocationRequest, locationCallback, null);
我在此位置调用中获取位置更新
locationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
super.onLocationResult(locationResult);
for (Location location : locationResult.getLocations()) {
// list of locations
}
}
};
我读到 locationResult.getLocations()
检索从最旧到最新排序的位置对象列表,
我无法理解我现在想要的只是获取用户位置。
对此有什么帮助吗?
最佳答案
您可以使用locationResult.getLastLocation()
来获取最新的可用位置。
来自文档:LocationResult.getLastLocation()
public Location getLastLocation ()
Returns the most recent location
available in this result, or null if no
locations are available.
关于java - 使用位置回调获取位置更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49707091/