Last active
September 1, 2018 12:48
-
-
Save alizhdanov/41ddba48594ae0078c9b41b6e2236b4a to your computer and use it in GitHub Desktop.
Promisified geolocation
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 getLocation = () => new Promise((resolve, reject) => { | |
const success = position => resolve(position); | |
const error = error => reject(error); | |
navigator.geolocation.getCurrentPosition(success, error); | |
}) | |
try { | |
const position = await getLocation(); | |
console.log(position); | |
} catch (err) { | |
console.error('Unable to get position', err); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment