Skip to content

Instantly share code, notes, and snippets.

@alizhdanov
Last active September 1, 2018 12:48
Show Gist options
  • Save alizhdanov/41ddba48594ae0078c9b41b6e2236b4a to your computer and use it in GitHub Desktop.
Save alizhdanov/41ddba48594ae0078c9b41b6e2236b4a to your computer and use it in GitHub Desktop.
Promisified geolocation
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