Complete the code to get the LocationManager system service.
val locationManager = getSystemService([1]) as LocationManager
The constant LOCATION_SERVICE is used to get the LocationManager system service in Android.
Complete the code to request location updates from the GPS provider.
locationManager.requestLocationUpdates([1], 1000L, 1f, locationListener)
The GPS_PROVIDER is used to get location updates from the GPS hardware.
Fix the error in the permission check for location access.
if (ContextCompat.checkSelfPermission(this, [1]) != PackageManager.PERMISSION_GRANTED) { // Request permission }
To check location permission, use ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION. Here, ACCESS_COARSE_LOCATION is correct.
Fill both blanks to create a LocationListener that logs location changes.
val locationListener = object : LocationListener {
override fun onLocationChanged(location: [1]) {
Log.d("Location", "Lat: " + location.[2])
}
}The onLocationChanged method receives a Location object. To get latitude, use the latitude property.
Fill all three blanks to create a location request with balanced power accuracy and interval.
val locationRequest = LocationRequest.create().apply {
priority = [1]
interval = [2]
fastestInterval = [3]
}Use PRIORITY_BALANCED_POWER_ACCURACY for balanced power use. Set interval to 10000 milliseconds and fastestInterval to 5000 milliseconds.