2

在 android 中有两个单独的函数来获取位置:

  • 获取上一个位置()
  • 获取当前位置()

getLastLocation 返回设备的最后一个已知位置,getCurrentLocation 通过查找最新(当前)位置返回设备的当前位置。getCurrentLocation 需要一些时间来计算 getLastLocation 不需要任何时间的位置。

在Huawei Location Kit中,我找到了location和getLastLocation()的fusedLocation回调。有什么方法可以像在android中那样获取当前位置。获得设备确切位置的最佳方法是什么?

4

1 回答 1

2

建议使用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);
    }
于 2021-12-02T01:33:40.763 回答