From a2c352ced0f4bf0a2a4e8be5148bea1794138e32 Mon Sep 17 00:00:00 2001 From: Eliot Date: Fri, 15 Nov 2024 11:55:19 +0800 Subject: [PATCH] fix android getCurrentLocation --- .../main/java/com/rnbridge/geofencing/GeofenceManager.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/rnbridge/geofencing/GeofenceManager.kt b/android/src/main/java/com/rnbridge/geofencing/GeofenceManager.kt index 8ce98a5..d676f97 100644 --- a/android/src/main/java/com/rnbridge/geofencing/GeofenceManager.kt +++ b/android/src/main/java/com/rnbridge/geofencing/GeofenceManager.kt @@ -21,6 +21,8 @@ import com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_ENTER import com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_EXIT import com.google.android.gms.location.GeofencingRequest import com.google.android.gms.location.LocationServices +import com.google.android.gms.location.Priority +import com.google.android.gms.tasks.CancellationTokenSource import com.google.gson.Gson import com.google.gson.reflect.TypeToken import java.util.Locale @@ -54,7 +56,10 @@ class GeofenceManager(private val context: Context) { val response = Arguments.createMap() val activity = (context as ReactApplicationContext).currentActivity ?: return val fusedLocationClient = LocationServices.getFusedLocationProviderClient(activity) - fusedLocationClient.lastLocation.addOnSuccessListener { location: Location? -> + fusedLocationClient.getCurrentLocation( + Priority.PRIORITY_HIGH_ACCURACY, + CancellationTokenSource().token + ).addOnSuccessListener { location: Location? -> if (location == null) { promise.reject(Error("Location is undefined")) return@addOnSuccessListener