Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

Geolocation is not working on my react native iOS emulator

$
0
0

I used Geolocation in my react native code to get the current position and it is working well on Android. But not work on iOS.

Here is my code

import Geolocation from "@react-native-community/geolocation";import Geocoder from "react-native-geocoder";_getCurrentLocation = () => {    Alert.alert("Get Location","Do you want to update your location?",        [            {                text: 'Cancel',                onPress: () => console.log('Cancel Pressed'),                style: 'cancel'            },            {                text: 'UPDATE', onPress: () => {                    Geolocation.setRNConfiguration({ skipPermissionRequests: true,                                    authorizationLevel: "always" });                    if (Platform.OS === 'ios') Geolocation.requestAuthorization();                    Geolocation.getCurrentPosition(                        info => {                            const position = { lat: info.coords.latitude, lng: info.coords.longitude }                            Geocoder.geocodePosition(position).then(res => {                                console.warn(res);                                const { updateUserState } = this.props;                                updateUserState({ position : position, country : res[0].countryCode, city : res[0].adminArea });                                this.setState({ position : position, country : res[0].countryCode, city : res[0].adminArea });                            })                                .catch(err => {                                    console.warn(err)                                    alert(JSON.stringify(err));                                })                        },                        error => {                             // alert("Sorry, we cann't get your location now, please check your permission!")                            alert(JSON.stringify(error));                            console.log(error)                         },                        {                            enableHighAccuracy: false,                            timeout: 3000,                            // maximumAge: 1000,                        },                    )                }            }        ],        { cancelable: false }    )}

I am getting the below error:

PERMISSION_DENIED: 1POSITION_UNAVAILABLE: 2TIMEOUT: 3code: 3message: "Unable to fetch location within 15.0s."

This is my info.plist:

<key>NSLocationAlwaysUsageDescription</key><string>This app requires access to you location.</string><key>NSLocationWhenInUseUsageDescription</key><string>This app requires access to you location.</string>

Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>