Skip to content

Instantly share code, notes, and snippets.

@kostovtd
Created October 4, 2022 15:43
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 kostovtd/9bbe9352c7ef6adfc313bac193b48424 to your computer and use it in GitHub Desktop.
Save kostovtd/9bbe9352c7ef6adfc313bac193b48424 to your computer and use it in GitHub Desktop.
// Don't forget to add the required permissions in your manifest file
fun gpsProvider() {
val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
}
fun networkProvider() {
val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)
}
fun passiveProvider() {
val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER)
}
// available for API >= 31
fun fusedProvider() {
val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
locationManager.getLastKnownLocation(LocationManager.FUSED_PROVIDER)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment