exported getLocation function for reusability

This commit is contained in:
Pete Gerlach
2024-06-11 13:35:38 +02:00
parent 5bddc03d5c
commit d5bdb496d8
2 changed files with 25 additions and 14 deletions

13
src/utils/location.js Normal file
View File

@@ -0,0 +1,13 @@
export const locationUtils = {
getCurrentLocation: () => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(async function(position) {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
return {lon: longitude, lat: latitude};
});
} else {
return {lon: null, lat: null};
}
}
}