1 year ago

#315891

test-img

Faisal Khawaj

I want to get currentlocation of user , I am getting current location in android and ios but not on android tablet

I am getting correct latitude and longitude in android and ios and showing the marker but this doesn't happen on tablet. I am not getting marker in tablet android , I have enable showUserLocation={true} as well.

useEffect(() => {
    const requestLocationPermission = async () => {
        if (Platform.OS === 'ios') {
            Geolocation.requestAuthorization('always').then((resp) => {
                console.log("ios response ", resp)
                Geolocation.getCurrentPosition(
                    (position) => {
                        console.log("position:::", position)
                        const { latitude, longitude } = position.coords;
                        setCurrentLatitude(latitude)
                        setCurrentLongitude(longitude)
                    },
                    (error) => {
                        // See error code charts below.
                        console.log(error.code, error.message);
                    },
                    { enableHighAccuracy: true, timeout: 20000 }
                );
            }).catch((e) => console.log("ios error ::", e))
        }
        else {
            try {
                const granted = await PermissionsAndroid.request(
                    PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
                    {
                        title: 'Location Access Required',
                        message: 'This App needs to Access your location',
                    },
                );
                if (granted === PermissionsAndroid.RESULTS.GRANTED) {
                    Geolocation.getCurrentPosition(
                        (position) => {
                            // console.log("position:::", position)
                            const { latitude, longitude } = position.coords;
                            setCurrentLatitude(latitude)
                            setCurrentLongitude(longitude)
                        },
                        (error) => {
                            // See error code charts below.
                            console.log(error.code, error.message);
                        },
                        { enableHighAccuracy: false, timeout: 20000 }
                    );

                } else {
                    setLocationStatus('Permission Denied');
                }
            } catch (err) {
                console.warn("Location error ::", err);
            }
        };
    }
    requestLocationPermission();
}, [])

This is what I have done

react-native

geolocation

react-native-maps

0 Answers

Your Answer

Accepted video resources