0
0
Android Kotlinmobile~10 mins

Location services in Android Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get the LocationManager system service.

Android Kotlin
val locationManager = getSystemService([1]) as LocationManager
Drag options to blanks, or click blank then click option'
ALOCATION_SERVICE
BLOCATION_MANAGER
CLOCATION_PROVIDER
DLOCATION_CLIENT
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect constants like LOCATION_MANAGER or LOCATION_PROVIDER.
Trying to cast to the wrong type.
2fill in blank
medium

Complete the code to request location updates from the GPS provider.

Android Kotlin
locationManager.requestLocationUpdates([1], 1000L, 1f, locationListener)
Drag options to blanks, or click blank then click option'
ALocationManager.NETWORK_PROVIDER
BLocationManager.GPS_PROVIDER
CLocationManager.PASSIVE_PROVIDER
DLocationManager.FUSED_PROVIDER
Attempts:
3 left
💡 Hint
Common Mistakes
Using NETWORK_PROVIDER when GPS location is needed.
Using a provider that does not exist like FUSED_PROVIDER.
3fill in blank
hard

Fix the error in the permission check for location access.

Android Kotlin
if (ContextCompat.checkSelfPermission(this, [1]) != PackageManager.PERMISSION_GRANTED) {
    // Request permission
}
Drag options to blanks, or click blank then click option'
AManifest.permission.INTERNET
BManifest.permission.ACCESS_WIFI_STATE
CManifest.permission.ACCESS_COARSE_LOCATION
DManifest.permission.ACCESS_NETWORK_STATE
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for unrelated permissions like INTERNET or WIFI_STATE.
Forgetting to check permissions before accessing location.
4fill in blank
hard

Fill both blanks to create a LocationListener that logs location changes.

Android Kotlin
val locationListener = object : LocationListener {
    override fun onLocationChanged(location: [1]) {
        Log.d("Location", "Lat: " + location.[2])
    }
}
Drag options to blanks, or click blank then click option'
ALocation
Blatitude
Clongitude
DLocationProvider
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter types like LocationProvider.
Accessing longitude instead of latitude when asked for latitude.
5fill in blank
hard

Fill all three blanks to create a location request with balanced power accuracy and interval.

Android Kotlin
val locationRequest = LocationRequest.create().apply {
    priority = [1]
    interval = [2]
    fastestInterval = [3]
}
Drag options to blanks, or click blank then click option'
ALocationRequest.PRIORITY_BALANCED_POWER_ACCURACY
B10000L
C5000L
DLocationRequest.PRIORITY_HIGH_ACCURACY
Attempts:
3 left
💡 Hint
Common Mistakes
Using PRIORITY_HIGH_ACCURACY when balanced power is requested.
Mixing up interval and fastestInterval values.