Created
September 7, 2020 10:39
-
-
Save yusufceylan/aae842836e175616b7aec467931d0699 to your computer and use it in GitHub Desktop.
Huawei Location Kit - Last Known Location
This file contains 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
fun getLastKnownLocation( | |
onSuccess: ((lastKnownLocation: Location?) -> Unit)? = null, | |
onFail: ((exception: Exception) -> Unit)? = null | |
) { | |
val task: Task<Location> = mFusedLocationProviderClient.lastLocation | |
task.addOnSuccessListener { lastKnowLocation -> | |
if (lastKnowLocation == null) { | |
LogUtils.d("LocationKit -> Last Known Location is empty") | |
} else { | |
val currentLatLng = LatLng( | |
lastKnowLocation.latitude, | |
lastKnowLocation.longitude | |
) | |
LogUtils.d("LocationKit -> Last Known Location: $currentLatLng") | |
} | |
// Notify | |
onSuccess?.invoke(lastKnowLocation) | |
}.addOnFailureListener { exception -> | |
LogUtils.d("LocationKit -> Failed to get Last Known Location with exception: ${exception.localizedMessage}") | |
// Notify | |
onFail?.invoke(exception) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment