Skip to content

Commit a01053b

Browse files
Merge pull request #8 from eliot-ye/master
fix android getCurrentLocation
2 parents 4e338db + a2c352c commit a01053b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: android/src/main/java/com/rnbridge/geofencing/GeofenceManager.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_ENTER
2121
import com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_EXIT
2222
import com.google.android.gms.location.GeofencingRequest
2323
import com.google.android.gms.location.LocationServices
24+
import com.google.android.gms.location.Priority
25+
import com.google.android.gms.tasks.CancellationTokenSource
2426
import com.google.gson.Gson
2527
import com.google.gson.reflect.TypeToken
2628
import java.util.Locale
@@ -54,7 +56,10 @@ class GeofenceManager(private val context: Context) {
5456
val response = Arguments.createMap()
5557
val activity = (context as ReactApplicationContext).currentActivity ?: return
5658
val fusedLocationClient = LocationServices.getFusedLocationProviderClient(activity)
57-
fusedLocationClient.lastLocation.addOnSuccessListener { location: Location? ->
59+
fusedLocationClient.getCurrentLocation(
60+
Priority.PRIORITY_HIGH_ACCURACY,
61+
CancellationTokenSource().token
62+
).addOnSuccessListener { location: Location? ->
5863
if (location == null) {
5964
promise.reject(Error("Location is undefined"))
6065
return@addOnSuccessListener

0 commit comments

Comments
 (0)