2

I am building an app in React-Native and need to have location access as per the requirement.

I have tried using react-native-fused-location for the same, as below.

           FusedLocation.setLocationInterval(20000);
           FusedLocation.setFastestLocationInterval(15000);
          FusedLocation.setSmallestDisplacement(10);

          FusedLocation.setLocationPriority(
            FusedLocation.Constants.HIGH_ACCURACY
          );
          FusedLocation.startLocationUpdates();


          FusedLocation.getFusedLocation().then(location => {

            if (location != null) {
              let initialPosition = JSON.stringify(location);
              this.state.latitude = location.latitude;
              this.state.longitude = location.longitude;
              this.state.timestamp = location.timestamp;
              this.state.initialPosition = initialPosition;


            } else {
              alert("Location unavailable, please try later");
            }
          }).catch(error => {  // fused location catch
             console.log("location retrieval failed");
          });

The only output, I am receiving with the above code, in case of Oreo 8.0.0 is E/request: 100.

also tried the other way as below

navigator.geolocation.watchPosition(
            location => {
              console.log("inside watchPosition location");
              if (location != null) {
                console.log("location is not null");
                let initialPosition = JSON.stringify(location.coords);
                this.state.latitude = location.coords.latitude;
                this.state.longitude = location.coords.longitude;
                this.state.timestamp = location.coords.timestamp;
                this.state.initialPosition = initialPosition;


              } else {
                alert("Location unavailable, please try later");
              }
            },
            error => {
              console.log("calling ShowHideActivityIndicator,  getLocationWithNavigate (ios)");

              this.ShowHideActivityIndicator(false);
              alert("location retrieval failed");
              console.log(error);
            },
            { timeout: 20000, enableHighAccuracy: true, distanceFilter: 10 }
          );

But getting same output in both of the above codes, that is unable to get the location specifically in Android Oreo 8.0.0. Even the location retrieving callback is not even called. Though in other versions, including Oreo 8.1.0, and lower version devices, including Marshmallow and Nougat, it seems working fine.

Though, if I turn on the fake GPS in Oreo 8.0.0, then it seems to be able to get the location. I am unable to figure out, what I am missing.

Narendra Singh
  • 3,990
  • 5
  • 37
  • 78

1 Answers1

0

mention to google document:

In an effort to reduce power consumption, Android 8.0 (API level 26) limits how frequently background apps can retrieve the user's current location. Apps can receive location updates only a few times each hour.Background Location Limits

Amir daraei
  • 63
  • 2
  • 12