Below is the code used for getting the location
private fun requestLocation() {
Utils.print("LocationUpdateService","request location per minute")
if (ActivityCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_COARSE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
return
}
if (locationRequest != null)
mFusedLocationClient?.requestLocationUpdates(
locationRequest!!,
locationCallback,
Looper.myLooper()!!
)
}
locationRequest = LocationRequest.create()
locationRequest?.apply {
fastestInterval = 1000 * (AppPreference.getLocationInterval(applicationContext)-AppPreference.getLocationInterval(applicationContext)/10)
interval = 1000 * AppPreference.getLocationInterval(applicationContext)
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
}
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(applicationContext)