Skip to content

alihamzaazhar/react-native-location-settings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@alihamzaazhar/react-native-location-settings

A React Native TurboModule that shows a Google Maps-style in-app dialog to enable system location — powered by Google Play Services ResolvableApiException.

Instead of redirecting the user to the Settings app, this library shows the system location dialog inside your app, exactly like Google Maps does.

Requires React Native 0.73+ with New Architecture (TurboModules).


Demo

Screen_recording_20260618_072613.webm

How it works

This library uses Google Play Services SettingsClient to trigger a ResolvableApiException, which presents the system location enable dialog directly within your app. The promise resolves true if location becomes available, or false if the user declines. If system location is already enabled, the promise resolves immediately without showing any dialog.


Installation

npm install @alihamzaazhar/react-native-location-settings

Android setup

  1. Pin Google Play Services location version

    In your root android/build.gradle, add to the ext block:

    ext {
        // ... other versions
        playServicesLocationVersion = "21.3.0"
    }
  2. Add the dependency in android/app/build.gradle

    dependencies {
        implementation "com.google.android.gms:play-services-location:${playServicesLocationVersion}"
    }
  3. Add location permissions to AndroidManifest.xml

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  4. Rebuild the app

    npx react-native run-android

    No manual linking needed — React Native autolinking handles the rest.


Usage

import LocationSettings from '@alihamzaazhar/react-native-location-settings';
import { PermissionsAndroid } from 'react-native';

async function setupLocation() {
  // Calling this shows the in-app GPS enable dialog immediately.
  // The dialog is displayed DURING this await — no separate step needed.
  // Resolves true if the user enabled it, false if they dismissed.
  const systemEnabled = await LocationSettings.checkAndEnableSystemLocation();

  if (!systemEnabled) {
    // User dismissed the dialog — handle accordingly
    return;
  }

  // Step 2: Request app-level location permission
  const granted = await PermissionsAndroid.request(
    PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
  );

  if (granted === PermissionsAndroid.RESULTS.GRANTED) {
    // Location is fully ready — start reading GPS
  }
}

API

checkAndEnableSystemLocation(): Promise<boolean>

Shows the Google Maps-style in-app dialog to enable system location (GPS).

Return value Meaning
true System location is on — either the user just enabled it or it was already on
false User dismissed or tapped "No thanks"

Requirements

Requirement Version
React Native 0.73+
Android minSdk 24+
Google Play Services Required on device
New Architecture Supported (TurboModule)

License

MIT © alihamzaazhar

About

Android system location enabler for React Native - shows Google Maps-style in-app location enable dialog

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors