mirror of https://github.com/tasks/tasks
Add PlayLocationProvider
parent
a57040119b
commit
f86963244d
@ -0,0 +1,21 @@
|
|||||||
|
package org.tasks.location
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
import com.google.android.gms.location.LocationServices
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
|
class PlayLocationProvider(private val context: Context) : LocationProvider {
|
||||||
|
@SuppressLint("MissingPermission")
|
||||||
|
override suspend fun currentLocation(): MapPosition = withContext(Dispatchers.IO) {
|
||||||
|
suspendCoroutine { cont ->
|
||||||
|
LocationServices.getFusedLocationProviderClient(context).lastLocation
|
||||||
|
.addOnSuccessListener {
|
||||||
|
cont.resumeWith(Result.success(MapPosition(it.latitude, it.longitude)))
|
||||||
|
}
|
||||||
|
.addOnFailureListener { cont.resumeWith(Result.failure(it)) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue