Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@inderisonline
Last active October 27, 2022 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inderisonline/edf56f6adfe232960db6e8eab11768bc to your computer and use it in GitHub Desktop.
Save inderisonline/edf56f6adfe232960db6e8eab11768bc to your computer and use it in GitHub Desktop.
CurrentLocationCoroutineWrapperImpl test example
class CurrentLocationCoroutineWrapperImpl(
private val fusedLocationProviderClient: FusedLocationProviderClient
) {
@RequiresPermission(
anyOf =
[
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
]
)
suspend fun getCurrentLocation(priority: Int) =
suspendCancellableCoroutine { cont ->
fusedLocationProviderClient.getCurrentLocation(
priority, null
).apply {
addOnSuccessListener { location: Location? ->
if (location == null) {
cont.resumeWithException(LocationNotFoundException())
} else {
cont.resume(location)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment