36 lines
904 B
JavaScript
36 lines
904 B
JavaScript
import React, { useState, useEffect } from 'react';
|
|
import { Platform, Text, View, StyleSheet } from 'react-native';
|
|
import * as Location from 'expo-location';
|
|
|
|
export default function GT2Service() {
|
|
const [location, setLocation] = useState(null);
|
|
const [errorMsg, setErrorMsg] = useState(null);
|
|
|
|
useEffect(() => {
|
|
(async () => {
|
|
let { status } = await Location.requestForegroundPermissionsAsync();
|
|
if (status !== 'granted') {
|
|
setErrorMsg('Permission to access location was denied');
|
|
return;
|
|
}
|
|
|
|
let location = await Location.getCurrentPositionAsync({});
|
|
setLocation(location);
|
|
})();
|
|
}, []);
|
|
|
|
let text = 'Waiting..';
|
|
if (errorMsg) {
|
|
text = errorMsg;
|
|
} else if (location) {
|
|
text = JSON.stringify(location);
|
|
}
|
|
|
|
return (
|
|
<View style={styles.container}>
|
|
<Text style={styles.paragraph}>{text}</Text>
|
|
</View>
|
|
);
|
|
}
|
|
|