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

Ios Unable to fetch location within 10.0s Problems help me

Open mertbuldur opened this issue 5 years ago • 2 comments

hello, i'm trying to get location instantly for an app but it doesn't work very efficiently. Sometimes the location is being taken, sometimes it is not. What could the problem be? {code: 3, message: "Unable to fetch location within 10.0s.", PERMISSION_DENIED: 1, POSITION_UNAVAILABLE: 2, TIMEOUT: 3}

mertbuldur avatar Jul 25 '20 19:07 mertbuldur

I am also having this problem....can get location on Android no problem. Will not get location on iOS..

async componentDidMount() { if (Platform.OS === 'ios') { this.getUserPosition(); } else { try { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, { title: 'Device current location permission', message: 'Allow app to get your current location', buttonNeutral: 'Ask Me Later', buttonNegative: 'Cancel', buttonPositive: 'OK', }, ); if (granted === PermissionsAndroid.RESULTS.GRANTED) { this.getUserPosition(); } else { console.log('Location permission denied'); } } catch (err) { console.warn(err); } } }

getUserPosition = () => { Geolocation.getCurrentPosition( (position) => { this.setState({ currentLat: position.coords.latitude, currentLong: position.coords.longitude, }); }, (error) => Alert.alert('Error', JSON.stringify(error)), {enableHighAccuracy: true, timeout: 1000, maximumAge: 1000}, ); this.watchID = Geolocation.watchPosition((position) => { this.setState({ currentLat: position.coords.latitude, currentLong: position.coords.longitude, }); }); };

"react": "16.13.1", "react-native": "0.63.2", "@react-native-community/geolocation": "^2.0.2",

<key>UIBackgroundModes</key>
<array>
	<string>location</string>
	<string>fetch</string>
</array>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Please Allow Location Services</string>

aaculp avatar Sep 12 '20 01:09 aaculp

So I fixed it by going into the simulator settings... Privacy => Location => {Your App} => Always Allow

aaculp avatar Sep 12 '20 01:09 aaculp