Location Services
GPS
Privacy Settings
Smartphone Features
App Permissions

Check if location services are enabled

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Checking whether location services are enabled is not the same thing as checking whether your app has permission to use location. Modern mobile platforms separate global device settings from app-specific authorization. Good code needs to understand both layers before assuming location access is available.

Check Global Location Availability on iOS

On iOS, the first global check is CLLocationManager.locationServicesEnabled(). That tells you whether location services are enabled at the device level.

swift
1import CoreLocation
2
3if CLLocationManager.locationServicesEnabled() {
4    print("Location services are enabled globally")
5} else {
6    print("Location services are disabled on the device")
7}

That is only the first half of the decision. Your app also needs an authorization status such as authorizedWhenInUse or authorizedAlways.

swift
1import CoreLocation
2
3let status = CLLocationManager.authorizationStatus()
4
5switch status {
6case .authorizedAlways, .authorizedWhenInUse:
7    print("App may use location")
8case .notDetermined:
9    print("Permission has not been requested yet")
10case .denied, .restricted:
11    print("App cannot use location")
12@unknown default:
13    print("Handle future authorization states")
14}

An app can fail even when services are globally enabled if the user denied the app-specific permission.

If the app depends heavily on location, that usually means the UI should react differently to each state instead of treating "no location" as one generic failure. A good app can tell the user whether to open system settings, respond to a permission prompt, or simply try again later.

Check Provider State on Android

On Android, a common pattern is to ask LocationManager whether the relevant providers are enabled.

kotlin
1import android.content.Context
2import android.location.LocationManager
3
4fun isLocationEnabled(context: Context): Boolean {
5    val manager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
6    return manager.isProviderEnabled(LocationManager.GPS_PROVIDER) ||
7           manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
8}

As on iOS, that does not automatically mean your app has permission. You still need runtime permission checks for fine or coarse location, depending on the feature.

kotlin
1import android.Manifest
2import android.content.pm.PackageManager
3import androidx.core.content.ContextCompat
4
5fun hasLocationPermission(context: Context): Boolean {
6    return ContextCompat.checkSelfPermission(
7        context,
8        Manifest.permission.ACCESS_FINE_LOCATION
9    ) == PackageManager.PERMISSION_GRANTED
10}

The correct application logic is usually "location is usable only if the device setting allows it and the app permission allows it."

It is also worth rechecking these states when the app returns to the foreground. Users can change global location settings or app-specific permission outside your app, so a one-time check at launch is often not enough.

Design the User Flow Carefully

From a user-experience standpoint, do not just fail silently when location is unavailable. Show the difference between:

  • location services disabled globally
  • app permission denied
  • permission not requested yet

Those states lead to different next steps. One may need a permission prompt. Another may need a deep link to system settings. Another may simply need a retry after the user turns location back on.

This distinction is especially important in apps for navigation, ride sharing, or nearby search, where location is central to the feature rather than optional.

Common Pitfalls

The most common mistake is checking only the global location-services state and forgetting app-specific permission. The app still cannot read location if the user denied access.

Another issue is treating GPS-only checks as if they covered every location mode. Depending on the platform and use case, network-based location may also matter.

People also often request permission before explaining why the feature needs it. That tends to lower acceptance and creates a worse recovery path when access is denied.

Summary

  • Location availability depends on both global device settings and app-specific permission.
  • On iOS, use CLLocationManager.locationServicesEnabled() and check authorization status separately.
  • On Android, check the enabled location providers and the runtime permission state.
  • Do not treat "services enabled" as proof that your app can actually read location.
  • Handle disabled services, denied permission, and not-yet-requested permission as different user states.

Course illustration
Course illustration

All Rights Reserved.