|
|
@ -1,20 +1,22 @@ |
|
|
|
import { useEffect, useState } from "react"; |
|
|
|
import * as Location from "expo-location"; |
|
|
|
|
|
|
|
export default function useLocation( |
|
|
|
defaultLocation = { longitude: 0.0, latitude: 0.0 } |
|
|
|
) { |
|
|
|
export default function useLocation(defaultLocation = { longitude: 0.0, latitude: 0.0 }) { |
|
|
|
const [location, setLocation] = useState(defaultLocation); |
|
|
|
|
|
|
|
const getLocation = async () => { |
|
|
|
try { |
|
|
|
const { granted } = await Location.requestPermissionsAsync(); |
|
|
|
|
|
|
|
if (!granted) return; |
|
|
|
|
|
|
|
const { |
|
|
|
coords: { latitude, longitude }, |
|
|
|
} = await Location.getLastKnownPositionAsync(); |
|
|
|
|
|
|
|
setLocation({ latitude, longitude }); |
|
|
|
} catch (error) { |
|
|
|
} |
|
|
|
catch (error) { |
|
|
|
console.log(error); |
|
|
|
} |
|
|
|
}; |
|
|
|