【问题标题】:getCurrentLocation in Huawei (HMS Location)getCurrentLocation in Huawei (HMS Location)
【发布时间】:2022-01-07 22:28:10
【问题描述】:
在 android 中有两个单独的函数来获取位置:
- getLastLocation()
- getCurrentLocation()
getLastLocation 返回设备的最后一个已知位置,getCurrentLocation 通过查找最新(当前)位置返回设备的当前位置。
getCurrentLocation 需要一些时间来计算 getLastLocation 不需要任何时间的位置。
在Huawei Location Kit中,我找到了location和getLastLocation()的fusedLocation回调。
有什么方法可以像在android中那样获取当前位置。
获取设备准确位置的最佳方法是什么?
【问题讨论】:
标签:
android
location
huawei-mobile-services
huawei-developers
huawei-location-kit
【解决方案1】:
建议您使用requestLocationUpdates获取当前位置信息,
在回调函数中,你会得到locationResult。
然后可以通过locationResult.getLocations()接口获取位置信息,如下图:
private final LocationCallback mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
super.onLocationResult(locationResult);
Log.d(TAG, "onLocationResult: " + locationResult);
Location location = locationResult.getLastLocation();
updateLocationLister(location);
}