How to use the expo-permissions.LOCATION function in expo-permissions

To help you get started, we’ve selected a few expo-permissions 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 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 calebnance / expo-uber / src / screens / Home.js View on Github external
async componentDidMount() {
    // get exisiting locaton permissions first
    const { status: existingStatus } = await Permissions.getAsync(
      Permissions.LOCATION
    );
    let finalStatus = existingStatus;

    // ask again to grant locaton permissions (if not already allowed)
    if (existingStatus !== 'granted') {
      const { status } = await Permissions.askAsync(Permissions.LOCATION);
      finalStatus = status;
    }

    // still not allowed to use location?
    if (finalStatus !== 'granted') {
      return;
    }

    const { coords } = await Location.getCurrentPositionAsync();
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 syousif94 / frugalmaps / buncha / utils / Permissions.js View on Github external
async function enableLocation() {
  const { status: askStatus } = await Permissions.getAsync(
    Permissions.LOCATION
  );

  if (IOS && askStatus === "denied") {
    Alert.alert(
      "Permission Denied",
      "To enable location, tap Open Settings, then tap on Location, and finally tap on While Using the App.",
      [
        { text: "Cancel", style: "cancel" },
        {
          text: "Open Settings",
          onPress: () => {
            Linking.openURL("app-settings:");
          }
        }
      ]
    );
github expo / expo / home / screens / GeofencingScreen.js View on Github external
didFocus = async () => {
    let { status } = await Permissions.askAsync(Permissions.LOCATION);

    if (status !== 'granted') {
      AppState.addEventListener('change', this.handleAppStateChange);
      this.setState({
        error:
          'Location permissions are required in order to use this feature. You can manually enable them at any time in the "Location Services" section of the Settings app.',
      });
      return;
    } else {
      this.setState({ error: null });
    }

    const { coords } = await Location.getCurrentPositionAsync();
    const isGeofencing = await Location.hasStartedGeofencingAsync(GEOFENCING_TASK);
    const geofencingRegions = await getSavedRegions();
github expo / expo / home / screens / LocationDiagnosticsScreen.js View on Github external
didFocus = async () => {
    let { status } = await Permissions.askAsync(Permissions.LOCATION);

    if (status !== 'granted') {
      AppState.addEventListener('change', this.handleAppStateChange);
      this.setState({
        error:
          'Location permissions are required in order to use this feature. You can manually enable them at any time in the "Location Services" section of the Settings app.',
      });
      return;
    } else {
      this.setState({ error: null });
    }

    const { coords } = await Location.getCurrentPositionAsync();
    const isTracking = await Location.hasStartedLocationUpdatesAsync(LOCATION_UPDATES_TASK);
    const task = (await TaskManager.getRegisteredTasksAsync()).find(
      ({ taskName }) => taskName === LOCATION_UPDATES_TASK
github expo / expo / apps / native-component-list / src / screens / PermissionsScreen.tsx View on Github external
onPress={() =>
                this.invokePermissionsFunction(
                  ...([
                    Permissions.CAMERA,
                    Permissions.AUDIO_RECORDING,
                    Permissions.LOCATION,
                    Permissions.USER_FACING_NOTIFICATIONS,
                    Permissions.NOTIFICATIONS,
                    Permissions.CONTACTS,
                    Permissions.SYSTEM_BRIGHTNESS,
                    Permissions.CAMERA_ROLL,
                    Permissions.CALENDAR,
                    Permissions.REMINDERS,
                  ] as Permissions.PermissionType[])
                )
              }
github syousif94 / frugalmaps / buncha / utils / Permissions.js View on Github external
{ text: "Cancel", style: "cancel" },
        {
          text: "Open Settings",
          onPress: () => {
            Linking.openURL("app-settings:");
          }
        }
      ]
    );
    throw new Error("Permission Denied");
  } else if (askStatus === "granted") {
    return;
  }

  const { status: locationStatus } = await Permissions.askAsync(
    Permissions.LOCATION
  );

  if (locationStatus !== "granted") {
    throw new Error("Permission Denied");
  }
}
github expo / expo / apps / native-component-list / src / screens / Location / LocationScreen.tsx View on Github external
_getSingleHeading = async () => {
    const { status } = await Permissions.askAsync(Permissions.LOCATION);
    if (status !== 'granted') {
      return;
    }

    try {
      this.setState({ searchingHeading: true });
      const heading = await Location.getHeadingAsync();
      this.setState({ singleHeading: heading, searchingHeading: false });
    } finally {
      this.setState({ searchingHeading: false });
    }
  }
github slorber / gatsby-plugin-react-native-web / examples / uikits / src / components / expo / ExpoPermissionsExample.js View on Github external
import * as Permissions from 'expo-permissions'
import React, { useEffect, useState } from 'react'
import { Button, ScrollView, Text, View } from 'react-native'

import Example from '../example'

const permissions = [
  ['CAMERA', Permissions.CAMERA],
  ['AUDIO_RECORDING', Permissions.AUDIO_RECORDING],
  ['LOCATION', Permissions.LOCATION],
  ['USER_FACING_NOTIFICATIONS', Permissions.USER_FACING_NOTIFICATIONS],
  ['NOTIFICATIONS', Permissions.NOTIFICATIONS],
  ['CONTACTS', Permissions.CONTACTS],
  ['SYSTEM_BRIGHTNESS', Permissions.SYSTEM_BRIGHTNESS],
  ['CAMERA_ROLL', Permissions.CAMERA_ROLL],
  ['CALENDAR', Permissions.CALENDAR],
  ['REMINDERS', Permissions.REMINDERS],
]

export default function PermissionsExample() {
  return (