Can we use the GPS antenna in way that we can control the polling speed? like every 10 seconds and every 1 second. Assume the power usage is manageable. I just want to get accurate location asap.
Asked
Active
Viewed 67 times
1 Answers
0
We can use Android default LocationManager class which is not google API.
And also Huawei Mapkit LocationManager
val locationManager = HuaweiLocationManager(this) locationManager.registerLocationUpdates(onSuccess = { viewModel.updateCurrentLocation(it) })
and subscribe to update in different speed.
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}")
}
}

Zinna
- 1,947
- 2
- 5
- 20