Closed rikopramayudi closed 3 years ago
same problem here
Have you tried putting playServicesVersion = "17.0.0"
? That works for me.
react-native-geolocation-service: 5.0.0
react-native: 0.62.2
react-native-camera: 3.23.1
@allanloji i have, but still "Unable to retrieve location"
I got this on iOS only, works fine on Android
@DeVoresyah I ran into this on iOS too. I was using NSLocationWhenInUseUsageDescription in Info.plist because I don't want the "Always" option. The only thing that "solved" it for me was to also enable NSLocationAlwaysAndWhenInUseUsageDescription in Info.plist. Somehow that fixed the "Unable to retrieve location" error and now "While Using the App" works. The downside is, of course, the "Always" option is visible (in Settings > [App Name] > Location) which I had hoped to avoid.
For android, are you facing this in real device or emulator ? If emulator, which one and which android version ? For iOS, I can't verify this cause I don't have ios devices.
Has anyone solved this issue? I am also facing the same issue. Geolocation.getCurrentPosition()
only works the first time. If I close the app and come back again it does not detect anything. No error message, nothing. the function does not even trigger.
@Saad-Bashar We are having the same issue on Android devices with react-native-geolocation-service
3.1.0. I found that the second try will fail without any error but the third requests and after succeed. So here's my workaround to this issue.
defaultOptions = {...};
// Async function to fetch location from react-native-geolocation-service
async function getCurrentPosition(options?: Object) {
return new Promise((resolve, reject) => {
let opt = defaultOptions;
if (options) {
opt = { ...defaultOptions, ...options };
}
Geolocation.getCurrentPosition(
data => {
resolve(data);
},
error => {
const errorMessage = `getCurrentPosition error: ${JSON.stringify(error)}`;
const errorObj = new Error(errorMessage);
notifyErrorParams(errorObj, { errorMessage });
reject(errorMessage);
},
opt,
);
});
}
// Retry when the request fails with timeout
async function getPosition() {
let didTimeOut = false;
return new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
didTimeOut = true;
getCurrentPosition().then(r => resolve(r));
}, 2000);
getCurrentPosition()
.then(r => {
clearTimeout(timeout);
if (!didTimeOut) {
resolve(r);
}
})
.catch(e => {
if (didTimeOut) {
return;
}
reject(e);
});
});
}
I'll try and see if this issue resolved on 5.0.0
Wow, this seems to be a super hack :/
Please try the new version and see if this issue exists. If so, feel free to open new issue.
I'm getting the same error, Unable to retrieve location, error code - 2
I'm using "react": "16.8.6", "react-native": "0.60.5", "react-native-geolocation-service": "^5.3.0-beta.1", iOS 14.4 and Xcode - 12.4
permission on app is ON (set to while using )
Check set location in debug of simulator
Try to add timeout in config
after first retrieve there's error log '2 Unable to retrieve location'
and if i put googlePlayServicesVersion = "17.0.0" that make comflict with react-native-camera so i not put that on build.gradle, is there any sugestion?
react-native-cli: 2.0.1 react-native: 0.62.2