How to use the expo-location.watchPositionAsync function in expo-location

To help you get started, we’ve selected a few expo-location 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 flow-typed / flow-typed / definitions / npm / expo-location_v5.x.x / flow_v0.104.x- / test_expo-location.js View on Github external
it('should raise an error when call function with invalid arguments', () => {
    // $ExpectError: first argument is required
    watchPositionAsync();

    // $ExpectError: first argument must be a n object
    watchPositionAsync(69);

    // $ExpectError: second argument must be a function
    watchPositionAsync({}, 69);

    watchPositionAsync(
      {
        // $ExpectError: invalid accuracy value
        accuracy: 1,
      },
      () => {}
    );
  });
});
github flow-typed / flow-typed / definitions / npm / expo-location_v5.x.x / flow_v0.104.x- / test_expo-location.js View on Github external
it('should passes when used properly', () => {
    watchPositionAsync({}, data => {
      const { coords, timestamp } = data;

      (timestamp: number);

      (coords.latitude: number);
      (coords.speed: number);

      // $ExpectError: check any
      (coords.speed: string);
    });
    watchPositionAsync({}, async () => {}).then(result => {
      result.remove();
    });
  });
github flow-typed / flow-typed / definitions / npm / expo-location_v5.x.x / flow_v0.104.x- / test_expo-location.js View on Github external
it('should raise an error when call function with invalid arguments', () => {
    // $ExpectError: first argument is required
    watchPositionAsync();

    // $ExpectError: first argument must be a n object
    watchPositionAsync(69);

    // $ExpectError: second argument must be a function
    watchPositionAsync({}, 69);

    watchPositionAsync(
      {
        // $ExpectError: invalid accuracy value
        accuracy: 1,
      },
      () => {}
    );
  });
});
github developmentseed / observe / app / services / trace.js View on Github external
async function startTrace (dispatch) {
  dispatch({
    type: types.TRACE_START
  })
  let { status } = await Permissions.askAsync(Permissions.LOCATION)
  if (status !== 'granted') {
    // TODO: show error message
  }
  const watcher = await Location.watchPositionAsync({
    accuracy: Location.Accuracy.BestForNavigation,
    timeInterval: 1000, // TODO: get from config
    distanceInterval: 5 // TODO: get from config
  }, location => {
    dispatch({
      type: types.TRACE_POINT_CAPTURED,
      location
    })
  })
  dispatch({
    type: types.TRACE_SET_SUBSCRIPTION,
    watcher
  })
}
github digidem / mapeo-mobile / src / frontend / context / LocationContext.js View on Github external
updateStatus = async () => {
    try {
      const hasLocationPermission =
        this.props.permissions[PERMISSIONS.ACCESS_FINE_LOCATION] ===
        RESULTS.GRANTED;
      if (!hasLocationPermission) return;
      clearTimeout(this._timeoutId);
      const provider = await Location.getProviderStatusAsync();
      // log("Provider status", provider);
      if (provider && provider.locationServicesEnabled && !this._watch) {
        this._watch = await Location.watchPositionAsync(
          positionOptions,
          this.onPosition
        );
      } else {
        if (this._watch) this._watch.remove();
        this._watch = null;
        this._timeoutId = setTimeout(this.updateStatus, LOCATION_TIMEOUT);
      }
      // If location services are disabled, clear the position stored in state,
      // so that we don't create observations with a stale position.
      if (!provider || !provider.locationServicesEnabled)
        this.setState({ position: undefined });
      this.setState({ provider });
    } catch (err) {
      this.handleError(err);
    }
github StephenGrider / rn-casts / tracks / src / hooks / useLocation.js View on Github external
const startWatching = async () => {
      try {
        await requestPermissionsAsync();
        subscriber = await watchPositionAsync(
          {
            accuracy: Accuracy.BestForNavigation,
            timeInterval: 1000,
            distanceInterval: 10
          },
          callback
        );
      } catch (e) {
        setErr(e);
      }
    };