mirror of
https://github.com/FoggedLens/deflock.git
synced 2026-06-11 00:27:54 +02:00
store current location in pinia
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref, type Ref } from 'vue';
|
||||
|
||||
export const useGlobalStore = defineStore('global', () => {
|
||||
const currentLocation: Ref<[number, number] | null> = ref(null);
|
||||
|
||||
const setCurrentLocation = (): Promise<[number, number]> =>
|
||||
new Promise((resolve, reject) => {
|
||||
if (navigator.geolocation) {
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
(position) => {
|
||||
currentLocation.value = [position.coords.latitude, position.coords.longitude];
|
||||
resolve([position.coords.latitude, position.coords.longitude]);
|
||||
},
|
||||
(error) => {
|
||||
reject(error);
|
||||
},
|
||||
{
|
||||
timeout: 10000,
|
||||
enableHighAccuracy: true,
|
||||
}
|
||||
);
|
||||
} else {
|
||||
reject(new Error('Geolocation is not supported by this browser.'));
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
currentLocation,
|
||||
setCurrentLocation,
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user