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.61k stars 292 forks source link

Null is not an object when trying to access the location in Android device #202

Closed prajna-h closed 2 years ago

prajna-h commented 4 years ago

Failing to get the location and gives null is not an object.

Environment react-native-cli: 2.0.1 react-native: 0.62.2

react-native-geolocation-service: ^5.0.0

buildToolsVersion = "28.0.3" minSdkVersion = 16 compileSdkVersion = 28 targetSdkVersion = 28 supportLibVersion = "27.1.1" googlePlayServicesAuthVersion = "17.0.0"

Android version - 10

 requestLocationPermission = async () => {
   let granted = await PermissionsAndroid.request(
       PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
        {
           title: "App Geolocation Permission",
           message: "App needs access to your phone's location.",
        }
  );

if (granted === PermissionsAndroid.RESULTS.GRANTED) {
  Geolocation.getCurrentPosition((position) => {
      console.log(position);
    },
    (error) => {
      console.log(error.code, error.message);
    },
    { enableHighAccuracy: false, timeout: 15000, maximumAge: 10000 }
  );
}
else {
  console.log('Location permission not granted!!!!');
 }
};

componentDidMount() {
  this.requestLocationPermission();
}
Agontuk commented 3 years ago

Sorry for the delay, this is most probably an issue with your setup. Please check if this library is integrated properly.

Agontuk commented 2 years ago

Closing due to inactivity