How to use the react-native-geolocation-service.getCurrentPosition function in react-native-geolocation-service

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 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 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 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 }
      );
    }
  }