How to use react-native-geolocation-service - 10 common examples

To help you get started, we’ve selected a few react-native-geolocation-service examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OriginProtocol / origin / mobile / src / components / origin-web3view.js View on Github external
async function requestLocationPermission() {
    if (Platform.OS === 'ios') {
      Geolocation.setRNConfiguration({
        authorizationLevel: 'whenInUse'
      })

      Geolocation.requestAuthorization()
      // IOS permission request does not offer a callback :/
      return null
    } else if (Platform.OS === 'android') {
      try {
        const granted = await PermissionsAndroid.request(
          PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
        )
        if (granted === PermissionsAndroid.RESULTS.GRANTED) {
          return true
        } else {
          return false
        }
      } catch (err) {
        console.warn(err.message)
        return false
      }
github OriginProtocol / origin / mobile / src / components / origin-web3view.js View on Github external
async function getCurrentPosition(callback) {
    const hasLocationPermission = await requestLocationPermission()
    /* This will only be fired on Android. On Apple we can not detect when/if a
     * location permission has been granted or denied. For that reason after a
     * predefined period we just timeout.
     */

    if (hasLocationPermission === false) {
      callback({
        locationAvailable: false,
        error: 'Can not obtain location permission'
      })
      return
    }

    Geolocation.getCurrentPosition(
      position => {
        callback({
          locationAvailable: true,
          position
        })
      },
      error => {
        callback({
          locationAvailable: false,
          error: error.message,
          errorCode: error.code
        })
      },
      { enableHighAccuracy: true, timeout: 20000, maximumAge: 10000 }
    )
  }
github OriginProtocol / origin / mobile / src / components / origin-web3view.js View on Github external
async function requestLocationPermission() {
    if (Platform.OS === 'ios') {
      Geolocation.setRNConfiguration({
        authorizationLevel: 'whenInUse'
      })

      Geolocation.requestAuthorization()
      // IOS permission request does not offer a callback :/
      return null
    } else if (Platform.OS === 'android') {
      try {
        const granted = await PermissionsAndroid.request(
          PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
        )
        if (granted === PermissionsAndroid.RESULTS.GRANTED) {
          return true
        } else {
          return false
        }
github pjay79 / BarsAppAmplify / app / features / App / Bars / NearbyBars / MapScreen.js View on Github external
getNearbyBars = () => {
    Geolocation.getCurrentPosition(
      (position) => {
        this.setState(
          {
            latitude: position.coords.latitude,
            longitude: position.coords.longitude,
          },
          () => {
            this.searchBars();
          },
        );
      },
      error => console.log(error),
      { enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 },
    );
  };
github Agontuk / react-native-geolocation-service / example / App.js View on Github external
this.setState({ loading: true }, () => {
      Geolocation.getCurrentPosition(
        (position) => {
          this.setState({ location: position, loading: false });
          console.log(position);
        },
        (error) => {
          this.setState({ location: error, loading: false });
          console.log(error);
        },
        { enableHighAccuracy: true, timeout: 15000, maximumAge: 10000, distanceFilter: 50, forceRequestLocation: true }
      );
    });
  }
github pjay79 / BarsAppAmplify / app / features / App / Bars / NearbyBars / ListScreen.js View on Github external
getNearbyBars = () => {
    if (this.mounted) {
      Geolocation.getCurrentPosition(
        (position) => {
          this.setState(
            {
              latitude: position.coords.latitude,
              longitude: position.coords.longitude,
            },
            () => {
              this.searchBars();
            },
          );
        },
        error => console.log(error),
        {
          enableHighAccuracy: true,
          timeout: 30000,
          maximumAge: 10000,
github pjay79 / BarsAppAmplify / app / screens / BarsScreen.js View on Github external
getNearbyBars = () => {
    if (this.mounted) {
      Geolocation.getCurrentPosition(
        (position) => {
          this.setState(
            {
              latitude: position.coords.latitude,
              longitude: position.coords.longitude,
            },
            () => {
              this.searchBars();
            },
          );
        },
        error => console.log(error),
        { enableHighAccuracy: false, timeout: 25000, distanceFilter: 0 },
      );
    }
  };
github Agontuk / react-native-geolocation-service / example / App.js View on Github external
this.setState({ updatesEnabled: true }, () => {
      this.watchId = Geolocation.watchPosition(
        (position) => {
          this.setState({ location: position });
          console.log(position);
        },
        (error) => {
          this.setState({ location: error });
          console.log(error);
        },
        { enableHighAccuracy: true, distanceFilter: 0, interval: 5000, fastestInterval: 2000 }
      );
    });
  }
github josephroquedev / campus-guide / src / containers / find / StartingPoint.tsx View on Github external
async _findClosestBuilding(): Promise {
    this.setState({ locating: true });

    const locationPermissionGranted = await Permissions.requestLocationPermission(Platform.OS, PermissionsAndroid);
    if (locationPermissionGranted) {
      Geolocation.getCurrentPosition((position: any) => {
        const location = { latitude: position.coords.latitude, longitude: position.coords.longitude };
        this.setState({
          closestBuilding: Navigation.findClosestBuilding(location, this.props.buildingList, MAXIMUM_DISTANCE),
          locating: false,
          locationError: undefined,
        });
      },
        (err: any) => this._showLocationErrorMessage(err),
        { enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
      );
    }
  }
github Agontuk / react-native-geolocation-service / example / App.js View on Github external
removeLocationUpdates = () => {
      if (this.watchId !== null) {
          Geolocation.clearWatch(this.watchId);
          this.setState({ updatesEnabled: false })
      }
  }