export const getLocation = (): Promise<{latitude: number, longitude: number, accuracy: number}> => { return new Promise((res, rej) => { // Check if Geolocation is supported if ("geolocation" in navigator) { // Request the current position navigator.geolocation.getCurrentPosition( (position) => { const latitude = position.coords.latitude; const longitude = position.coords.longitude; const accuracy = position.coords.accuracy; return res({ latitude, longitude, accuracy }) }, (error) => { return rej(error); }, { enableHighAccuracy: true, // Optional: more accurate results timeout: 5000, // Optional: wait time in ms before timing out maximumAge: 0 // Optional: no caching } ); } else { return rej("Geolocation is not supported by this browser."); } }) } export default getLocation