react-native-geolocation icon indicating copy to clipboard operation
react-native-geolocation copied to clipboard

How to get location even with airplane mode active?

Open Mynameisjohndev opened this issue 10 months ago • 2 comments
trafficstars

I created this simple implementation, but when airplane mode is on it doesn't get the location, if I turn it off it normally gets it again. This same situation also happens in the react-native-geolocation-service library, however this project here is mine and I expose and use the expo-location and with it even with airplane mode active it captures it, why doesn't this library here capture the location with airplane mode active?

my implemenation ` import { Text } from 'react-native'; import { useEffect } from 'react'; import { SafeAreaView } from 'react-native-safe-area-context'; import Geo from '@react-native-community/geolocation';

export default function App() { const requestLocation = async () => { try { Geo.watchPosition((res)=>{ console.log(res); }, (e)=>{ console.log(e); },{ distanceFilter: 0, interval: 1000, fastestInterval: 500 }) } catch (error) { console.error('Erro ao tentar acessar a localização:', error); } };

useEffect(() => { requestLocation(); }, []);

return ( <SafeAreaView> <Text>Exemple</Text> </SafeAreaView> ); }

`

Mynameisjohndev avatar Jan 19 '25 21:01 Mynameisjohndev

It probably needs to use GNSS(https://developer.android.com/reference/android/location/LocationManager#GPS_PROVIDER) to work in airplane mode, otherwise it normally uses a combination of GPS, Wi-Fi and cell tower signals to calculate the location.

mensonones avatar Jan 19 '25 21:01 mensonones

Try this, @Mynameisjohndev

https://github.com/mensonones/rn-gps

mensonones avatar Jan 21 '25 01:01 mensonones