Skip to content

Commit

Permalink
fix android getCurrentLocation
Browse files Browse the repository at this point in the history
  • Loading branch information
eliot-ye committed Nov 15, 2024
1 parent 4e338db commit a2c352c
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a2c352c

Please sign in to comment.