I think you can use

navigator.geolocation.getCurrentPosition(
  (position) => {
   //do stuff with location
  },
  (error) => {
    this.setState({locationEnabled: false}),
  },
  {enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
);

For opening settings from your app, I think you will have to get your hands dirty with native code :D

Answer from Aakash Sigdel on Stack Overflow
🌐
npm
npmjs.com › package › react-native-android-location-enabler
react-native-android-location-enabler - npm
import { promptForEnableLocationIfNeeded } from 'react-native-android-location-enabler'; import { Platform } from 'react-native'; async function handleEnabledPressed() { if (Platform.OS === 'android') { try { const enableResult = await promptForEnableLocationIfNeeded(); console.log('enableResult', enableResult); // The user has accepted to enable the location services // data can be : // - "already-enabled" if the location services has been already enabled // - "enabled" if user has clicked on OK button in the popup } catch (error: unknown) { if (error instanceof Error) { console.error(error.m
      » npm install react-native-android-location-enabler
    
Published   Jul 28, 2025
Version   3.0.1
Discussions

android - Checking if location services are enabled using react native - Stack Overflow
I am currently working on an app using react native that requires location services to be on for some of its features. I have been researching if there is a simple way to test if the user has them More on stackoverflow.com
🌐 stackoverflow.com
[expo] Alert user when he disabled GPS location sharing while using app
I haven't used expo for a while and this might not be the optimal solution, but I'd do the following: expo's Location module has this method https://docs.expo.io/versions/latest/sdk/location/#locationgetlastknownpositionasyncoptions - it's useful in this case as it returns null if the last know position is stale. That's how you can identify that something isn't right and do your checks again. I've added one function in your code that does what you want ("checkLocationAvailability", called inside watchPositionAsync callback). import React, { useState, useEffect } from "react"; import { Alert, StyleSheet, Text, View } from "react-native"; import * as Location from "expo-location"; export default function App() { const [location, setLocation] = useState(null); const [watchId, setWatchId] = useState(null); const [locationEnabled, setLocationEnabled] = useState(false); useEffect(() => { (async () => { await Location.hasServicesEnabledAsync(); setLocationEnabled(true); console.log("location enabled"); })(); }, []); const checkLocationAvailability = async () => { const pos = await Location.getLastKnowPositionAsync({ // This should be equal or more than timeInterval in watchPositionAsync maxAge: 10000, // Can use the same as in watchPositionAsync or less requiredAccuracy: Location.Accuracy.Highest, }); if (!pos) { // This means position wasn't updated after the desired interval, // is that because they turned the location off? try { await Location.hasServicesEnabledAsync(); } catch () { setLocationEnabled(false); } } }; useEffect(() => { Location.watchPositionAsync( { accuracy: Location.Accuracy.Highest, distanceInterval: 1, timeInterval: 10000, }, (pos) => { setLocation(pos.coords); // Added this checkLocationAvailability(); } ) .then((locationWatcher) => { //set locationwatcher for removing setWatchId(locationWatcher); }) .catch((err) => { setLocationEnabled(false); console.log("watchpositon error: ", err.message); }); return () => { watchId && watchId.remove(); }; }, []); useEffect(() => { if (!locationEnabled) Alert.alert("You need to enable location sharing"); }, [locationEnabled]); return ( {JSON.stringify(location)} ); } More on reddit.com
🌐 r/reactnative
7
1
April 12, 2021
ios - Determining if geolocation enabled with react native - Stack Overflow
You can use this library https://github.com/yonahforst/react-native-permissions to check if user has accepted location permission. More on stackoverflow.com
🌐 stackoverflow.com
How to know when GPS was enabled?
I want to know how to check if the gps was enabled by the user after the displayed dialog or before. I mean, using you method there could be 2 stages: LocationServicesDialogBox.checkLocationService... More on github.com
🌐 github.com
13
July 28, 2017
🌐
GitHub
github.com › Richou › react-native-android-location-enabler › issues › 28
Check if location is enabled without opening modal · Issue #28 · Richou/react-native-android-location-enabler
September 19, 2019 - It will be nice to have a function that only checks if the location is turned on instead of asking to turn it on. Useful in case for localize icons such as Google Maps. if GPS is off, localize the show question mark icon. 👍React with 👍3ahmedam55, tuiza and msultanic
Author   Richou
🌐
GitHub
github.com › YsnKsy › react-native-location-enabler
GitHub - YsnKsy/react-native-location-enabler: This package makes it easy for an React Native App to ensure that the Android device's system settings are properly configured for the app's location needs. If your app needs to request location, the device needs to enable the appropriate system settings, such as GPS or Wi-Fi scanning. Rather than directly enabling services such as the device's GPS, your app specifies the required level of accuracy/power consumption, and the device automatically makes the appro
import LocationEnabler from 'react-native-location-enabler'; let listener = null; function cb(result) { const { locationEnabled } = result; console.log(`Location are ${locationEnabled ? 'enabled' : 'disabled'}`); if (listener !== null) { // remove listener when you finish listener.remove(); } } listener = LocationEnabler.addListener(cb);
Starred by 164 users
Forked by 24 users
Languages   TypeScript 41.0% | Java 28.1% | Kotlin 24.4% | JavaScript 6.5%
🌐
Expo Documentation
docs.expo.dev › expo sdk › location
Location - Expo Documentation
Checks whether location services are enabled by the user. ... A promise which fulfills to true if location services are enabled on the device, or false if not. ... A promise which fulfills with boolean value indicating whether the geofencing task is started or not. ... A promise which fulfills with boolean value indicating whether the location task is started or not. ... Polyfills navigator.geolocation for interop with the core React Native and Web API approach to geolocation.
🌐
Reddit
reddit.com › r/reactnative › [expo] alert user when he disabled gps location sharing while using app
r/reactnative on Reddit: [expo] Alert user when he disabled GPS location sharing while using app
April 12, 2021 -

I'm building an expo google maps based app. I'm monitoring the user's location with watchPositionAsync() . I want to alert the user that he needs to enable location sharing if he disables it while using the app. Just like in google maps navigation.

So if I'm following a tour and if I disable location sharing from the mobile dropdown for example, I want to prompt an alert to enable it, because without the user's current location the navigation should not work.

The problem with this code is :

  • When I first time come to this component and I accept location sharing, then later if I disable location sharing while using the app, I don't get an alert. I need to use setLocationEnabled(true); somewhere but I don't know where

  • When I first come to this component and decline location sharing the first time, then if I enable location sharing again it won't get detected.

import React, { useState, useEffect } from "react";
import { Alert, StyleSheet, Text, View } from "react-native";
import * as Location from "expo-location";

export default function App() {
  const [location, setLocation] = useState(null);
  const [watchId, setWatchId] = useState(null);
  const [locationEnabled, setLocationEnabled] = useState(false);

  useEffect(() => {
    (async () => {
      await Location.hasServicesEnabledAsync();
      setLocationEnabled(true);
      console.log("location enabled");
    })();
  }, []);

  useEffect(() => {
    Location.watchPositionAsync(
      {
        accuracy: Location.Accuracy.Highest,
        distanceInterval: 1,
        timeInterval: 10000,
      },
      (pos) => {
        setLocation(pos.coords);
      }
    )
      .then((locationWatcher) => {
        //set locationwatcher for removing
        setWatchId(locationWatcher);
      })
      .catch((err) => {
        setLocationEnabled(false);
        console.log("watchpositon error: ", err.message);
      });

    return () => {
      watchId && watchId.remove();
    };
  }, []);

  useEffect(() => {
    if (!locationEnabled) Alert.alert("You need to enable location sharing");
  }, [locationEnabled]);

  return (
    <View style={styles.container}>
      <Text style={styles.paragraph}>{JSON.stringify(location)}</Text>
    </View>
  );
}

Can somebody please help me? I've been stuck at this for days and haven't found any similar questions/answers.

Top answer
1 of 1
3
I haven't used expo for a while and this might not be the optimal solution, but I'd do the following: expo's Location module has this method https://docs.expo.io/versions/latest/sdk/location/#locationgetlastknownpositionasyncoptions - it's useful in this case as it returns null if the last know position is stale. That's how you can identify that something isn't right and do your checks again. I've added one function in your code that does what you want ("checkLocationAvailability", called inside watchPositionAsync callback). import React, { useState, useEffect } from "react"; import { Alert, StyleSheet, Text, View } from "react-native"; import * as Location from "expo-location"; export default function App() { const [location, setLocation] = useState(null); const [watchId, setWatchId] = useState(null); const [locationEnabled, setLocationEnabled] = useState(false); useEffect(() => { (async () => { await Location.hasServicesEnabledAsync(); setLocationEnabled(true); console.log("location enabled"); })(); }, []); const checkLocationAvailability = async () => { const pos = await Location.getLastKnowPositionAsync({ // This should be equal or more than timeInterval in watchPositionAsync maxAge: 10000, // Can use the same as in watchPositionAsync or less requiredAccuracy: Location.Accuracy.Highest, }); if (!pos) { // This means position wasn't updated after the desired interval, // is that because they turned the location off? try { await Location.hasServicesEnabledAsync(); } catch () { setLocationEnabled(false); } } }; useEffect(() => { Location.watchPositionAsync( { accuracy: Location.Accuracy.Highest, distanceInterval: 1, timeInterval: 10000, }, (pos) => { setLocation(pos.coords); // Added this checkLocationAvailability(); } ) .then((locationWatcher) => { //set locationwatcher for removing setWatchId(locationWatcher); }) .catch((err) => { setLocationEnabled(false); console.log("watchpositon error: ", err.message); }); return () => { watchId && watchId.remove(); }; }, []); useEffect(() => { if (!locationEnabled) Alert.alert("You need to enable location sharing"); }, [locationEnabled]); return ( {JSON.stringify(location)} ); }
Find elsewhere
🌐
npm
npmjs.com › package › react-native-location-enabler
react-native-location-enabler - npm
April 14, 2022 - 'enabled' : 'disabled' }`); ); // Define configuration const config = { priority: HIGH_ACCURACY, // default BALANCED_POWER_ACCURACY alwaysShow: true, // default false needBle: false, // default false }; // Check if location is enabled or not checkSettings(config); // If location is disabled, prompt the user to turn on device location requestResolutionSettings(config); // ... // Removes this subscription listener.remove(); ... git clone https://github.com/YsnKsy/react-native-location-enabler.git && cd react-native-location-enabler
      » npm install react-native-location-enabler
    
Published   Apr 14, 2022
Version   4.1.1
Author   Yassine Kassy
🌐
GitHub
github.com › webyonet › react-native-android-location-services-dialog-box › issues › 21
How to know when GPS was enabled? · Issue #21 · webyonet/react-native-android-location-services-dialog-box
July 28, 2017 - I want to know how to check if ... or before. ... LocationServicesDialogBox.checkLocationServicesIsEnabled({ message: "", cancel: "", ok: "" }) .then(function (success) {}) .catch((error) => { });...
Author   webyonet
🌐
React Native Archive
archive.reactnative.dev › docs › geolocation
🚧 Geolocation · React Native Archive
enableHighAccuracy (bool) - Is a boolean representing if to use GPS or not. If set to true, a GPS position will be requested. If set to false, a WIFI location will be requested. distanceFilter (m) - The minimum distance from the previous location to exceed before returning a new location. Set to 0 to not filter locations. Defaults to 100m. useSignificantChanges (bool) - Uses the battery-efficient native significant changes APIs to return locations.
Top answer
1 of 3
26

So I am going to start answering my own question.

For GPS:

there seems to be a sensible solution. IOS seems to natively request if there is a geolocation request. And for Android this is not natively supported but someone has created a module for that ( https://github.com/webyonet/react-native-android-location-services-dialog-box )

so in my action creator I added the next code:

if(Platform.OS === 'android')
LocationServicesDialogBox.checkLocationServicesIsEnabled({ 
                message: "<h2>Use Location?</h2> \
                            This app wants to change your device settings:<br/><br/>\
                            Use GPS for location<br/><br/>", 
                ok: "YES", 
                cancel: "NO" 
            }).then(() => { 
                locationTracking(dispatch, getState, geolocationSettings)
            })

For Network: There is no native support for neither so i end up doing my own action creator to check.

export function networkCheck(){
  return (dispatch) => {
    const dispatchNetworkState = (isConnected) => dispatch({
      type: types.NETWORK_STATE,
      state: isConnected
    })
    const handle = () => NetInfo.isConnected.fetch().done(dispatchNetworkState)
    NetInfo.isConnected.addEventListener('change', handle);
  }
}

A little extra:

for GPS i added this to check if the user goes and disable GPS on the middle of the task.

export function locationCheck(geolocationSettings = {enableHighAccuracy: true, timeout: 20000, maximumAge: 10000, distanceFilter:10}){
  return (dispatch) => {
    navigator.geolocation.watchPosition(
        () => {
            dispatch({
                type: types.LOCATION_STATE,
                state: true
            })
        },
        () => {
            dispatch({
                type: types.LOCATION_STATE,
                state: false
            })
        },
        geolocationSettings)
  }
}
2 of 3
16

For enabling location/gps on Android I can recommend this module: https://github.com/Richou/react-native-android-location-enabler

It is using the standard Android dialog for location:

🌐
Medium
medium.com › @kinley.tshering › geolocation-in-react-native-9d76c50d2ffb
Geolocation in React Native. Using the react-native-location for… | by Kinley Tshering | Medium
November 26, 2019 - We mention the required permissions ... the required permissions. To check if the app has the required permissions, use the checkPermission method....
🌐
mobile
folio3.com › home › handling background location permissions in react native
Handling Background Location Permissions in React Native - Mobile App Development Services
September 23, 2021 - However, to enable this, the user must be navigated to the app settings. In the case of the Android version is below 10, this step is not required and using ACCESS_FINE_LOCATION will do the work. The process is similar to iOS and this is how it can be achieved: if (Platform.Version < 29) { alwaysPermission = PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION; } else { alwaysPermission = PERMISSIONS.ANDROID.ACCESS_BACKGROUND_LOCATION; } }
🌐
npm
npmjs.com › package › @react-native-community › geolocation › v › 3.0.1
react-native-community/geolocation
September 14, 2022 - In order to enable geolocation in the background, you need to include the 'NSLocationAlwaysUsageDescription' key in Info.plist and add location as a background mode in the 'Capabilities' tab in Xcode.
      » npm install @react-native-community/geolocation
    
Published   Sep 01, 2024
Version   3.0.1
Author   React Native Community
🌐
npm
npmjs.com › package › react-native-location-settings-enabler
react-native-location-settings-enabler - npm
July 24, 2020 - import LocationSettingsEnabler from "react-native-location-settings-enabler" ... Checking if the user's device location is turned on / off.
      » npm install react-native-location-settings-enabler
    
Published   Jul 24, 2020
Version   3.0.1
Author   Yassine Kassy
🌐
Skypack
skypack.dev › view › react-native-location-enabler
npm:react-native-location-enabler | Skypack
August 8, 2020 - 'enabled' : 'disabled' }`); ); // Define configuration const config = { priority: HIGH_ACCURACY, // default BALANCED_POWER_ACCURACY alwaysShow: true, // default false needBle: false, // default false }; // Check if location is enabled or not checkSettings(config); // If location is disabled, prompt the user to turn on device location requestResolutionSettings(config); // ... // Removes this subscription listener.remove(); ... git clone https://github.com/YsnKsy/react-native-location-enabler.git && cd react-native-location-enabler
🌐
npm
npmjs.com › package › react-native-android-location-services-dialog-box
react-native-android-location-services-dialog-box - npm
August 2, 2019 - // used only when "providerListener" is enabled · LocationServicesDialogBox.stopListener(); // Stop the "locationProviderStatusChange" listener · } import LocationServicesDialogBox from "react-native-android-location-services-dialog-box"; LocationServicesDialogBox.checkLocationServicesIsEnabled({ message: "<font color='#f1eb0a'>Use Location ?</font>", ok: "YES", cancel: "NO", style: { // (optional) backgroundColor: '#87a9ea',// (optional) positiveButtonTextColor: '#ffffff',// (optional) positiveButtonBackgroundColor: '#5fba7d',// (optional) negativeButtonTextColor: '#ffffff',// (optional) ne
      » npm install react-native-android-location-services-dialog-box