Skip to content

Commit

Permalink
feat(android): add getLastLocation to FusedLocationProvider (#13133)
Browse files Browse the repository at this point in the history
* feat(android): add getLastLocation to FusedLocationProvider

* use existing method
  • Loading branch information
m1ga committed Oct 7, 2022
1 parent 9202366 commit 0155e42
Showing 1 changed file with 17 additions and 0 deletions.
Expand Up @@ -11,6 +11,7 @@

import android.annotation.SuppressLint;
import android.content.Context;
import android.location.Location;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -27,6 +28,7 @@
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;

import org.appcelerator.kroll.common.Log;
Expand Down Expand Up @@ -141,6 +143,7 @@ private static abstract class PlayServices
private static final ArrayList<LocationProviderProxy> fusedLocationQueue = new ArrayList<>();
private static final ArrayList<LocationProviderProxy> fusedLocationProviders = new ArrayList<>();

@SuppressLint("MissingPermission")
public static void init(Context context, final GeolocationModule geolocationModule)
{
// requires Google Play Services 11.0.0+ or later
Expand Down Expand Up @@ -177,6 +180,20 @@ public void onConnectionFailed(@NonNull ConnectionResult connectionResult)

if (fusedLocationClient == null) {
fusedLocationClient = LocationServices.getFusedLocationProviderClient(context);

// try to get last known location
if (geolocationModule.hasLocationPermissions()) {
fusedLocationClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>()
{
@Override
public void onSuccess(Location location)
{
if (location != null) {
geolocationModule.onLocationChanged(location);
}
}
});
}
}
}
}
Expand Down

0 comments on commit 0155e42

Please sign in to comment.