How to use the expo-location.Accuracy 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 expo / expo / apps / native-component-list / src / screens / Location / LocationScreen.tsx View on Github external
_startWatchingLocation = async () => {
    const { status } = await Permissions.askAsync(Permissions.LOCATION);
    if (status !== 'granted') {
      return;
    }

    const subscription = await Location.watchPositionAsync(
      {
        accuracy: Location.Accuracy.High,
        timeInterval: 1000,
        distanceInterval: 1,
      },
      location => {
        // tslint:disable-next-line no-console
        console.log(`Got location: ${JSON.stringify(location.coords)}`);
        this.setState({ watchLocation: location });
      }
    );

    this.setState({ subscription });
  }
github developmentseed / observe / app / components / GPSTracker.js View on Github external
startWatching = async () => {
    let { status } = await Permissions.askAsync(Permissions.LOCATION)
    if (status !== 'granted') {
      // TODO: show error message
    }
    await Location.watchPositionAsync({
      accuracy: Location.Accuracy.BestForNavigation,
      timeInterval: 1000,
      distanceInterval: 5
    }, location => {
      console.log('location', location)
    })
  }
github expo / expo / home / screens / LocationDiagnosticsScreen.js View on Github external
onAccuracyChange = () => {
    const next = Location.Accuracy[this.state.accuracy + 1];
    const accuracy = next ? Location.Accuracy[next] : Location.Accuracy.Lowest;

    this.setState({ accuracy });

    if (this.state.isTracking) {
      // Restart background task with the new accuracy.
      this.startLocationUpdates(accuracy);
    }
  };
github digidem / mapeo-mobile / src / frontend / context / LocationContext.js View on Github external
type AppStateType = "active" | "background" | "inactive";

type Props = {
  children: React.Node,
  permissions: PermissionsType
};

const defaultContext: LocationContextType = {
  error: false
};

const positionOptions = {
  // See https://docs.expo.io/versions/v32.0.0/sdk/location/#locationaccuracy
  // this is the best possible accuracy using GPS and other sensors
  accuracy: Location.Accuracy.BestForNavigation,
  // This is the interval between location updates. We should get a new GPS
  // reading every 2000ms.
  timeInterval: 2000
};

// Timeout between location updates --> means location was probably turned off
// so we need to check it.
const LOCATION_TIMEOUT = 10000;

const LocationContext = React.createContext(
  defaultContext
);

/**
 * The LocationProvider provides details about the current device location based
 * on sensors including GPS. It must be included in the component heirarchy
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 expo / expo / apps / native-component-list / src / screens / Location / BackgroundLocationMapScreen.tsx View on Github external
import * as TaskManager from 'expo-task-manager';

import Button from '../../components/Button';
import Colors from '../../constants/Colors';

const STORAGE_KEY = 'expo-home-locations';
const LOCATION_UPDATES_TASK = 'location-updates';

const locationEventsEmitter = new EventEmitter();

const locationAccuracyStates: { [key in Location.Accuracy]: Location.Accuracy } = {
  [Location.Accuracy.Lowest]: Location.Accuracy.Low,
  [Location.Accuracy.Low]: Location.Accuracy.Balanced,
  [Location.Accuracy.Balanced]: Location.Accuracy.High,
  [Location.Accuracy.High]: Location.Accuracy.Highest,
  [Location.Accuracy.Highest]: Location.Accuracy.BestForNavigation,
  [Location.Accuracy.BestForNavigation]: Location.Accuracy.Lowest,
};

const locationActivityTypes: { [key in Location.ActivityType]: Location.ActivityType | undefined } = {
  [Location.ActivityType.Other]: Location.ActivityType.AutomotiveNavigation,
  [Location.ActivityType.AutomotiveNavigation]: Location.ActivityType.Fitness,
  [Location.ActivityType.Fitness]: Location.ActivityType.OtherNavigation,
  [Location.ActivityType.OtherNavigation]: Location.ActivityType.Airborne,
  [Location.ActivityType.Airborne]: undefined,
};

interface Props {
  navigation: NavigationScreenProp<{}, any>;
}

interface State {
github expo / expo / apps / native-component-list / src / screens / Location / BackgroundLocationMapScreen.tsx View on Github external
import MapView from 'react-native-maps';
import * as Location from 'expo-location';
import * as Permissions from 'expo-permissions';
import * as TaskManager from 'expo-task-manager';

import Button from '../../components/Button';
import Colors from '../../constants/Colors';

const STORAGE_KEY = 'expo-home-locations';
const LOCATION_UPDATES_TASK = 'location-updates';

const locationEventsEmitter = new EventEmitter();

const locationAccuracyStates: { [key in Location.Accuracy]: Location.Accuracy } = {
  [Location.Accuracy.Lowest]: Location.Accuracy.Low,
  [Location.Accuracy.Low]: Location.Accuracy.Balanced,
  [Location.Accuracy.Balanced]: Location.Accuracy.High,
  [Location.Accuracy.High]: Location.Accuracy.Highest,
  [Location.Accuracy.Highest]: Location.Accuracy.BestForNavigation,
  [Location.Accuracy.BestForNavigation]: Location.Accuracy.Lowest,
};

const locationActivityTypes: { [key in Location.ActivityType]: Location.ActivityType | undefined } = {
  [Location.ActivityType.Other]: Location.ActivityType.AutomotiveNavigation,
  [Location.ActivityType.AutomotiveNavigation]: Location.ActivityType.Fitness,
  [Location.ActivityType.Fitness]: Location.ActivityType.OtherNavigation,
  [Location.ActivityType.OtherNavigation]: Location.ActivityType.Airborne,
  [Location.ActivityType.Airborne]: undefined,
};

interface Props {
github expo / expo / home / screens / LocationDiagnosticsScreen.js View on Github external
const STORAGE_KEY = 'expo-home-locations';
const LOCATION_UPDATES_TASK = 'location-updates';

const locationEventsEmitter = new EventEmitter();

export default class LocationDiagnosticsScreen extends React.Component {
  static navigationOptions = {
    title: 'Location Diagnostics',
  };

  mapViewRef = React.createRef();

  state = {
    isBackgroundLocationAvailable: null,
    accuracy: Location.Accuracy.High,
    isTracking: false,
    showsBackgroundLocationIndicator: false,
    savedLocations: [],
    initialRegion: null,
    error: null,
  };

  componentDidMount() {
    this.checkBackgroundLocationAvailability();
  }

  async checkBackgroundLocationAvailability() {
    const isBackgroundLocationAvailable = await Location.isBackgroundLocationAvailableAsync();
    this.setState({ isBackgroundLocationAvailable });
  }