Agontuk / react-native-geolocation-service

React native geolocation service for iOS and android
https://www.npmjs.com/package/react-native-geolocation-service
MIT License
1.6k stars 291 forks source link

Geolocation.getCurrentPosition not working on iOS 14.5 #290

Closed renanogueiraa closed 3 years ago

renanogueiraa commented 3 years ago

As it says in the title, I'm having trouble getting the library to work in my app on iOS 14.5 (while Android is ok!) As much as it asks for permission and I give it, it keeps returning an error saying that the location for the app was not allowed. And I have all the permissions on Info.plist too, as I previously used the react-native-geolocation library and it was working for iOS normally...

Is there anything I can do to make it work? it's the first time i'm using the lib.

The code:

const hasPermission = await hasGeolocationPermission();

if (hasPermission) {
    Geolocation.getCurrentPosition(({ coords }) => {
        params.latitude = coords.latitude;
        params.longitude = coords.longitude;

        navigation.navigate('FoodBasketList', params);
        setSearching(false);
    },
    error => {
        toast.show({ message: getGeolocationError(error.code), duration: 4000 });
        setSearching(false);
    },
    { 
        enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 
    });
}

The second code:

export async function grantGeolocationPermission() {
    if (Platform.OS === 'android') {
        const granted = await PermissionsAndroid.requestMultiple(['android.permission.ACCESS_FINE_LOCATION', 'android.permission.ACCESS_COARSE_LOCATION']);
        return granted;
    }

    const granted = await Geolocation.requestAuthorization('whenInUse');
    return granted === 'granted';
}

Thanks guys!

jdrorrer commented 3 years ago

@renanogueiraa Were you able to get this working? I get Location request timed out on iOS 14.4.2+, but it works fine everywhere else.

jdrorrer commented 3 years ago

I think this should be re-opened.

It looks like the problem is the errorCallback is called no matter what if you manually set the timeout value, since the timerFired selector will run at the end of the Timer's timeInterval: https://github.com/Agontuk/react-native-geolocation-service/blob/de29b69c90b37530bdbb190eb8d58b4ea537ac20/ios/RNFusedLocation.swift#L164

I've got a fix locally that seems to be working. I can push up a PR if needed.

Edit: Never mind, I created a new ticket here: https://github.com/Agontuk/react-native-geolocation-service/issues/291