Created
October 4, 2022 15:43
-
-
Save kostovtd/9bbe9352c7ef6adfc313bac193b48424 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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