Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from "react";
- import {
- Platform,
- Text,
- View,
- StyleSheet,
- Linking,
- Button,
- AppState
- } from "react-native";
- import Constants from "expo-constants";
- import * as TaskManager from "expo-task-manager";
- import * as Location from "expo-location";
- import * as Permissions from "expo-permissions";
- import * as IntentLauncher from "expo-intent-launcher";
- import { Alert, NavigationActions } from "react-native";
- import Modal from "react-native-modal";
- const LOCATION_TASK_NAME = "background-location-task";
- export default class LocationScreen extends Component {
- state = {
- location: null,
- errorMessage: null,
- };
- componentDidMount = async () => {
- await Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, {
- accuracy: Location.Accuracy.Balanced
- });
- render() {
- let text = "Waiting..";
- if (this.state.errorMessage) {
- text = this.state.errorMessage;
- } else if (this.state.location) {
- text = JSON.stringify(this.state.location);
- }
- return (
- <View style={styles.container}>
- <Text style={styles.paragraph}>{text}</Text>
- </View>
- );
- }
- }
- TaskManager.defineTask(LOCATION_TASK_NAME, handel);
- export async function handel({ data, error }) {
- try {
- let { status } = await Permissions.askAsync(Permissions.LOCATION);
- if (status !== "granted") {
- this.setState({
- errorMessage: "Permission to access location was denied"
- });
- return;
- } else {
- if (data) {
- const { locations } = data;
- const location = locations.map(location => {
- let newLocation = Location.reverseGeocodeAsync(location.coords).then(
- data => {
- let maplocation = data.map(location => {
- console.log(location);
- console.log(location.city);
- });
- }
- );
- });
- }
- }
- } catch (error) {
- let status = Location.getProviderStatusAsync();
- if (!status.locationServiceEnabled) {
- const { navigation } = this.props;
- navigation.navigate("Login");
- }
- }
- }
- const styles = StyleSheet.create({
- container: {
- flex: 1,
- alignItems: "center",
- justifyContent: "center",
- paddingTop: Constants.statusBarHeight,
- backgroundColor: "#ecf0f1"
- },
- paragraph: {
- margin: 24,
- fontSize: 18,
- textAlign: "center"
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement