@boneframework/native-components
Version:
Expo React Native Components for Bone Framework
32 lines (22 loc) • 691 B
text/typescript
import {useEffect, useState} from "react";
import * as Location from "expo-location";
const useLocation = () => {
const [location, setLocation] = useState({});
const getLocation = async () => {
try {
const {granted} = await Location.requestForegroundPermissionsAsync();
if (!granted) {
return;
}
const {coords: {longitude, latitude}} = await Location.getLastKnownPositionAsync();
setLocation({latitude, longitude})
} catch (e) {
console.log(e)
}
}
useEffect(() => {
getLocation();
}, []);
return location;
};
export default useLocation;