Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private fun fetchLastKnownLocation() {
- fusedLocationClient.lastLocation.addOnSuccessListener {
- lastLocation = it
- value = lastLocation
- }
- }
- private fun getCurrentLocation() {
- val locationRequest = createLocationRequest()
- val builder = LocationSettingsRequest.Builder()
- .addLocationRequest(locationRequest)
- val client: SettingsClient = LocationServices.getSettingsClient(activity)
- val task: Task<LocationSettingsResponse> = client.checkLocationSettings(builder.build())
- task.addOnSuccessListener { _ ->
- fusedLocationClient.requestLocationUpdates(locationRequest, locationCallback, null)
- }
- task.addOnFailureListener { exception ->
- when (exception) {
- is ResolvableApiException -> {
- exception.startResolutionForResult(activity, REQUEST_CHECK_SETTINGS)
- }
- else -> {
- postValue(null)
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment