2

In android there are two separate functions to get Location:

  • getLastLocation()
  • getCurrentLocation()

getLastLocation returns the last known location of the device where, getCurrentLocation returns current location of the device by finding latest (current) location. getCurrentLocation takes some time to calculate where getLastLocation does not take any time.

In Huawei Location Kit, I found fusedLocation callback for location and getLastLocation(). Is there any method to get Current Location as in android. And what is the best way to get exact location of the device?

Faizan Ahmad
  • 352
  • 4
  • 20

1 Answers1

1

You are advised to use requestLocationUpdates to get current location information, In the callback function, you will get the locationResult.

Then you can get the location information by locationResult.getLocations() interface, like below:

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);
    }
zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
  • Can you share your code to get location on `Huawei` because when I use `FusedLocationProviderClient` then it works on all devices but only `Huawei` mobile its not working and show me pop-up that `"Your device is not supported Google Play Service"`? Is it possible to get the location in all devices using any single code? – Ninja Feb 08 '23 at 10:34