Created
September 7, 2020 11:16
-
-
Save yusufceylan/81217c6f2d0f910af73f62f60025accf to your computer and use it in GitHub Desktop.
Huawei Location Kit - Request Location Updates
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 registerLocationUpdates( | |
interval: Long = 10000, | |
onSuccess: ((location: Location?) -> Unit)? = null, | |
onFail: ((locationAvailability: LocationAvailability?) -> Unit)? = null | |
) { | |
val mLocationRequest = LocationRequest() | |
// Set the location update interval (in milliseconds). | |
mLocationRequest.interval = interval | |
// Set the weight. | |
mLocationRequest.priority = LocationRequest.PRIORITY_HIGH_ACCURACY | |
// Create location callback | |
if (mLocationCallback == null) | |
mLocationCallback = createLocationCallback(onSuccess, onFail) | |
// Request location update | |
mFusedLocationProviderClient.requestLocationUpdates( | |
mLocationRequest, | |
mLocationCallback, | |
Looper.getMainLooper() | |
) | |
.addOnSuccessListener { | |
// Requesting location updates is started successfully. | |
LogUtils.d("LocationKit -> Start Location Updates Successfully") | |
} | |
.addOnFailureListener { exception -> | |
// Failed to start location updates. | |
LogUtils.d("LocationKit -> Start Location Updates Failed with exception: ${exception.localizedMessage}") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment