Hi,
My setup is
"dependencies": {
"@react-native-community/geolocation": "^1.4.2",
"react": "16.8.6",
"react-native": "0.60.4",
"react-native-geolocation-service": "^3.0.0",
"react-native-gesture-handler": "^1.3.0",
"react-navigation": "^3.11.1"
},
And code is:
Geolocation.getCurrentPosition(
(position) => {
console.warn("Position " + position.coords.latitude + " " + position.coords.longitude);
},
(error) => {
// See error code charts below.
console.warn("Error " + error.code, error.message);
},
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000, }
);
Scenario:
When the Location in top drawer menu is ON then I am getting location.
But when Location is off, it is not showing the following popup to ask user to enable the location service:

Instead, it directly goes to (error) and says, "error.code = 2, No location provider available."
I think in earlier versions of library this used to work. But facing this problem in 3.0.0.
Any help on this would be appreciated.
P.S. @Agontuk Thanks for this library. We really appreciate your efforts.
You have both @react-native-community/geolocation & react-native-geolocation-service installed. Make sure you're importing the correct library in your component. I tried 3.0.0 in my example project and the dialog is showing up correctly.
On another note, remove all android related setup described in README file. It is not needed in RN60 as it'll integrate the module automatically when installed.
@Agontuk I understand these things.
import Geolocation from 'react-native-geolocation-service';
I have added @react-native-community/geolocation module because when I ran it on iOS, it was asking to link this module to app, I searched about it and got to know that in RN 0.60 geolocation is removed as built in module and now is available as a separate module. And library had internal dependency on that so I had to install that as well.
a. After installing @react-native-community/geolocation Location is working fine on iOS.
b. On Android it wasn't working even when I had not added @react-native-community/geolocation
As you said it I just created a new empty project and integrated this library, but unfortunately the result is same. I am not getting popup.
"dependencies": {
"react": "16.8.6",
"react-native": "0.60.4",
"react-native-geolocation-service": "^3.0.0"
},
import Geolocation from 'react-native-geolocation-service';
---
componentDidMount() {
// Instead of navigator.geolocation, just use Geolocation.
Geolocation.getCurrentPosition(
(position) => {
console.warn(position);
},
(error) => {
// See error code charts below.
console.warn(error.code, error.message);
},
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
);
}
I have mentioned the ACCESS_FINE_LOCATION in Manifest file and enabled the permission for app from settings.
What Android version are you using on your device when this happens?
@oakis I have tested on two devices with Android 8.0 and Android 7.0
@Android773 Can you try with Android 9? Might be a similar issue a bunch of others have been experiencing.
@oakis I tried with Android 9 as well, but it is not asking to turn Location Service on when Location is off.
have you solved this issue?
Getting the same issue in Android version 9, package version 3.0.0 and RN version 0.60.4. No solutions so far.
@prasan2421 Which React Native version you are using?
Same for us with GPS Sensor deactivated on Android:
"react-native": "0.60.4",
"@react-native-community/geolocation": "^1.4.2",
"react-native-geolocation-service": "^3.0.0",
Tested on an Android 9 Device:
Geolocation.getCurrentPosition(
pos => {
// does not go here
},
err => {
// ends up here
// err.code = 2
// err.message: No location provider available
},
{
enableHighAccuracy: true,
timeout: 20000,
maximumAge: 120000,
showLocationDialog: true,
forceRequestLocation: true
}
);
on iOS it works (when deactivating the locationService in device settings it reports back as no permission for app though)
@prasan2421 Which React Native version you are using?
v 0.60.4
Remove @react-native-community/geolocation": "^1.4.2", plugin and try
as stated before, that is a dependency for the plugin to work with iOS.
Is it possible this is an issue with the "@react-native-community/geolocation" plugin instead which is causing this one to show this behaviour?
Remove @react-native-community/geolocation": "^1.4.2", plugin and try
i havent kept this plugin yet i have the issue, but im using @react-native-community/netinfo.
Did you solve this issue by removing @react-native-community/geolocation?
Guys, can anyone give me a sample project for this issue ? I am running an example with RN60 in my mobile and location popup is working fine for me. Also please provide any steps necessary to reproduce this.
Guys, can anyone give me a sample project for this issue ? I am running an example with RN60 in my mobile and location popup is working fine for me. Also please provide any steps necessary to reproduce this.
https://github.com/prasan2421/location-test-project
Above is the link to my repo.
I've created a fresh RN project of version 0.60.4 and installed react-native-geolocation-service version 3.0.0. i have not kept any other package but the issue is still there. It looks like a bug of new react native itself.
I have the same issue.
Android 9
React Native: v0.60.4
react-native-geolocation-service: v 3.0.0
It seems like PR #68 introduced an additional check to determine whether location providers are enabled or not. If no providers are available, it'll immediately return error response instead of showing popup.
This check is needed because it enables us to request location even when location setting is set to Device Only.
We may need to find an alternate solution. What are your thoughts guys ?
so will this issue be fixed? i was also wondering how few others above managed to make this working.
Guys, let me know if this flow makes sense. Looping in @cladjules since he implemented the forceRequestLocation feature.
1) If location settings are ok, it'll invoke success callback with location
2) If not ok and showLocationDialog is false, it'll invoke error callback with codeSETTINGS_NOT_SATISFIED.
3) If not ok and showLocationDialog is true, it'll show location popup to improve location accuracy.
4) If user clicks OK, it'll update the location settings and invoke success callback with location.
5) If user clicks NO THANKS and forceRequestLocation is false, it'll invoke error callback with codeSETTINGS_NOT_SATISFIED.
6) If user clicks NO THANKS and forceRequestLocation is true but location provider is not enabled, it'll invoke error callback with code POSITION_UNAVAILABLE.
7) If user clicks NO THANKS and forceRequestLocation is true and location provider is enabled, it'll invoke success callback with location if it's possible.
@Agontuk Sounds good to me.
I have the same problem (of course in Android)
With RN < 0.60.0 and this library < 3.0.0. After grant permission, it will show dialog request to turn on GPS and then everything fine.
With RN >= 0.60.0 and this library >= 3.0.0. After grant permission, it won't show dialog request to turn on GPS and throw error message: 'No location provider available.', code: 2. So I have to turn on GPS manually on the device.
And about @react-native-community/geolocation, we have to install it for iOS working, but I think the issue won't relative to this geolocation since when I haven't installed it, the issue still happens on Android.
Did anyone get any solution? Thanks.
Fixed in 3.1.0
Everything's fine, thanks to @Agontuk
@Agontuk Great!
It is working fine after updating to 3.1.0.
Thanks a lot.
Guys, let me know if this flow makes sense. Looping in @cladjules since he implemented the
forceRequestLocationfeature.
- If location settings are ok, it'll invoke success callback with location
- If not ok and
showLocationDialogisfalse, it'll invoke error callback with codeSETTINGS_NOT_SATISFIED.- If not ok and
showLocationDialogistrue, it'll show location popup to improve location accuracy.- If user clicks
OK, it'll update the location settings and invoke success callback with location.- If user clicks
NO THANKSandforceRequestLocationisfalse, it'll invoke error callback with codeSETTINGS_NOT_SATISFIED.- If user clicks
NO THANKSandforceRequestLocationistruebut location provider is not enabled, it'll invoke error callback with codePOSITION_UNAVAILABLE.- If user clicks
NO THANKSandforceRequestLocationistrueand location provider is enabled, it'll invoke success callback with location if it's possible.
@Agontuk, @cladjules : this works as intended, in my case I have the options
{
enableHighAccuracy: true,
timeout: 15000,
maximumAge: 1000 * 60 * 3,
forceRequestLocation: true,
showLocationDialog: true,
}
and I see the dialogue about improving location by activating Location Services, I can answer 'No, thanks' and I still get a location! Thanks for the work btw.
This is great because I do have a few users for whom activating the Google Location Services isn't an option but many others for whom it's fine.
However, for users without these Google Location Services, it seems the dialogue will show every single time my app needs to grab the location. Which might quickly become annoying for them since the main interaction in my app makes the app ask for the current location.
Is that the way you guys deliver this or did I miss some way to be more user-friendly? By only showing that dialogue once and remembering to force without dialogue afterwards for instance?
Hi!
Using [email protected] (react-native 0.61.3 Android 6), calling
Geolocation.watchPosition(successCb, errorCb, {
enableHighAccuracy: true,
interval: 20000,
showLocationDialog: true,
useSignificantChanges: true,
})
the location dialog doesn't appear if the GPS is off and it results in error callback {"code": 2, "message": "No location provider available."}.
The dialog appears calling getCurrentPosition instead.
Is it the right behaviour? Should I call getCurrentPosition and afterwards watchPosition?
Thank you!
@fabripeco Check for permissions first I guess https://facebook.github.io/react-native/docs/permissionsandroid
No, I get the necessary permissions before calling watchPosition. Actually when I call getCurrentPosition, the location dialog is shown and GPS is turned on when I click Ok. The problem raises only with watchPosition and GPS turned off. Something wrong with my code? Ideas?
I get this issue using Android Studio Emulator of a Pixel 2 API 30 using Android 10.0+ and having chosen in my location settings to "Ask every time". It always triggers the error callback. Is this specific to using an emulator?
I get this issue using Android Studio Emulator of a Pixel 2 API 30 using Android 10.0+ and having chosen in my location settings to "Ask every time". It always triggers the error callback. Is this specific to using an emulator?
I'm also having this issue on Android 10.0 API 29 on a Nexus S emulator. And even trying to set force to true is not making the pop up to show.
Any idea?
$ react-native info
System:
OS: Linux 5.1 Arch Linux undefined
CPU: (6) x64 Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz
Memory: 1.20 GB / 15.59 GB
Shell: 5.7.1 - /usr/bin/zsh
Binaries:
Node: 12.10.0 - /usr/bin/node
Yarn: 1.17.3 - /usr/bin/yarn
npm: 6.11.3 - /usr/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
Android SDK:
API Levels: 16, 26, 28, 29
Build Tools: 26.0.3, 28.0.3, 29.0.0, 30.0.1
System Images: android-16 | Intel x86 Atom, android-16 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
Android NDK: 21.0.6113669
npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.1 => 0.61.1
npmGlobalPackages:
react-native-cli: 2.0.1
I get this issue using Android Studio Emulator of a Pixel 2 API 30 using Android 10.0+ and having chosen in my location settings to "Ask every time". It always triggers the error callback. Is this specific to using an emulator?
Unable to reproduce this, using the same emulator. Can you provide reproducible steps ?
Also I don't think location service popup will be shown in android 10+ devices, because location mode is no longer available in those api versions.
**React Native iOS**
***As you can see my code that the location popup permission is not showing in iOS, while I am using "react-native-geolocatio-service". I am struggling with, please help me, it would be more appreciable.****
onPressLocation = () => {
var that = this;
async function requestLocationPermission() {
const options = {
maxWidth: 500,
maxHeight: 500,
storageOptions: {
skipBackup: true,
},
};
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: 'ThoughtBulb App location Permission',
message: 'ThoughtBulb App needs access to your location ',
},
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
Geolocation.getCurrentPosition(
position => {
const currentLongitude = JSON.stringify(position.coords.longitude);
const currentLatitude = JSON.stringify(position.coords.latitude);
that.setState({
currentLatitude: currentLatitude,
currentLongitude: currentLongitude,
});
},
error => {
console.log(error);
},
{enableHighAccuracy: true, timeout: 15000, maximumAge: 10000},
);
} else {
alert('Location Permission is denied.');
}
}
if (Platform.OS === 'android') {
requestLocationPermission();
} else {
*****Here I need to get iOS location permission popup before execute below funtion.
I think this issue raised after updated the Xcode from 10 to 12***
Geolocation.getCurrentPosition(
position => {
const currentLongitude = JSON.stringify(position.coords.longitude);
const currentLatitude = JSON.stringify(position.coords.latitude);
that.setState({
currentLatitude: currentLatitude,
currentLongitude: currentLongitude,
});
},
error => {
console.log(error);
},
{enableHighAccuracy: true, timeout: 15000, maximumAge: 10000},
);
}
};
@Deepak13312 also have the same problem, haven't found a solution to it.
Most helpful comment
Fixed in
3.1.0