Guest User

Untitled

a guest
Jul 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. private fun fetchLastKnownLocation() {
  2. fusedLocationClient.lastLocation.addOnSuccessListener {
  3. lastLocation = it
  4. value = lastLocation
  5. }
  6. }
  7.  
  8. private fun getCurrentLocation() {
  9. val locationRequest = createLocationRequest()
  10. val builder = LocationSettingsRequest.Builder()
  11. .addLocationRequest(locationRequest)
  12.  
  13. val client: SettingsClient = LocationServices.getSettingsClient(activity)
  14. val task: Task<LocationSettingsResponse> = client.checkLocationSettings(builder.build())
  15.  
  16. task.addOnSuccessListener { _ ->
  17. fusedLocationClient.requestLocationUpdates(locationRequest, locationCallback, null)
  18. }
  19.  
  20. task.addOnFailureListener { exception ->
  21. when (exception) {
  22. is ResolvableApiException -> {
  23. exception.startResolutionForResult(activity, REQUEST_CHECK_SETTINGS)
  24. }
  25. else -> {
  26. postValue(null)
  27. }
  28. }
  29. }
  30. }
Add Comment
Please, Sign In to add comment