Created
October 3, 2022 10:47
-
-
Save mCzolko/f8673cde02fadc299cf3a9fe52417c63 to your computer and use it in GitHub Desktop.
Geolocation typescript function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const geolocation = (): Promise<GeolocationPosition> => new Promise((resolve, reject) => { | |
const geo = navigator.geolocation | |
if (!geo) { | |
reject('Geolocation is not supported') | |
return | |
} | |
geo.getCurrentPosition( | |
resolve, | |
err => reject(err.message) | |
) | |
}) | |
export default geolocation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment