Skip to content

QueenieCplusplus/React_geoApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React_geoApp

geo-location

expo install

$ expo install expo-location

Codebase

  import React, { useState, useEffect } from 'react';
  import { Text, View } from 'react-native';
  import * as Location from 'expo-location';

  export default function App() {

    const [location, setLocation] = useState(null);
    const [errorMsg, setErrorMsg] = useState(null);
    

    useEffect(() => {
    
      (async () => {
        let { status } = await Location.requestPermissionsAsync();
        if (status !== 'granted') {
          setErrorMsg('Permission to access location was denied');
        }

        let location = await Location.getCurrentPositionAsync({});
        setLocation(location);
        
      })
      
      ();
      
    });
    
    

    let text = 'Waiting..';
    
    
    if (errorMsg) {
    
      text = errorMsg;
      
    } else if (location) {
    
      text = JSON.stringify(location);
      
    }
    

    return (
    
      <View>
      
        <Text>{text}</Text>
        
      </View>
      
    );
    
    

  }