Closed raghvendra007 closed 2 years ago
Parameter is a string, not an object.
Geolocation.requestAuthorization("whenInUse");
when result is disabled ,it is showing popup to enable location services and just dissaper, how to hold the pop for for few second or how can i stop popup coming on screen ,location services is off then result is coming disabled in IOS
which version are you using ?
Hi, I'm also facing the same issue. Seems the "Turn On Location Service" prompt is a bit unreliable on iOS.
getCurrentPosition
will only show for a brief moment.watchPosition
will show normally.My current workaround is to check for the disabled
value from the requestAuthorization
and show my own prompt. (Not written in the sample code)
"react-native": "0.63.4", "react-native-geolocation-service": "^5.3.0-beta.1"
Code to reproduce:
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React from 'react';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
StatusBar,
Button,
PermissionsAndroid,
Platform,
} from 'react-native';
import Geolocation from 'react-native-geolocation-service';
const getPermission = () => {
if (Platform.OS === 'android') {
PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: 'Hello',
message: 'Please allow location access',
buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
},
).then((granted) => console.log(granted));
} else {
Geolocation.requestAuthorization('whenInUse')
.then((granted) => console.log(granted));
}
};
const getCurrentLocation = () => {
Geolocation.getCurrentPosition(
(position) => {
console.log(position);
},
(error) => {
console.log(error);
},
{
enableHighAccuracy: true,
timeout: 10000,
maximumAge: 10000,
showLocationDialog: false
}
);
};
const startWatchPosition = () => {
Geolocation.watchPosition(
(position) => {
console.log(position);
},
(error) => {
console.log(error);
},
);
};
const stopObserving = () => {
Geolocation.stopObserving();
};
const App: () => React$Node = () => {
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView>
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={styles.scrollView}>
<View style={styles.body}>
<Button title="Get Permission" onPress={() => getPermission()} />
<Button
title="Get Current Position"
onPress={() => getCurrentLocation()}
/>
<Button
title="Start Watch Position"
onPress={() => startWatchPosition()}
/>
<Button
title="Stop Watch Position"
onPress={() => stopObserving()}
/>
</View>
</ScrollView>
</SafeAreaView>
</>
);
};
const styles = StyleSheet.create({
scrollView: {},
engine: {
position: 'absolute',
right: 0,
},
body: {
backgroundColor: 'white',
},
sectionContainer: {
marginTop: 32,
paddingHorizontal: 24,
},
sectionTitle: {
fontSize: 24,
fontWeight: '600',
color: 'black',
},
sectionDescription: {
marginTop: 8,
fontSize: 18,
fontWeight: '400',
},
highlight: {
fontWeight: '700',
},
footer: {
fontSize: 12,
fontWeight: '600',
padding: 4,
paddingRight: 12,
textAlign: 'right',
},
});
export default App;
Please try the latest version. Closing this for now as I've failed to reproduce it.
I'm also witnessing the same issue with the latest version of the library.
I'm still struggling with this using version 5.3.1
😢
Geolocation.requestAuthorization({ authorizationLevel : "whenInUse" }).then(res=> console.log("result>>",res) ) response came ,"disabled" but it throw popup and in fraction of seconds pop up disseaper in IOS ,iphonex device