Skip to content

Instantly share code, notes, and snippets.

@yusufceylan
Created September 7, 2020 11:16
Show Gist options
  • Save yusufceylan/81217c6f2d0f910af73f62f60025accf to your computer and use it in GitHub Desktop.
Save yusufceylan/81217c6f2d0f910af73f62f60025accf to your computer and use it in GitHub Desktop.
Huawei Location Kit - Request Location Updates
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