Skip to content

Instantly share code, notes, and snippets.

@varmais
Created October 1, 2015 19:43
Show Gist options
  • Select an option

  • Save varmais/74586ec1854fe288d393 to your computer and use it in GitHub Desktop.

Select an option

Save varmais/74586ec1854fe288d393 to your computer and use it in GitHub Desktop.
Geolocation to Promise wrap example
var getPosition = function (options) {
return new Promise(function (resolve, reject) {
navigator.geolocation.getCurrentPosition(resolve, reject, options);
});
}
getPosition()
.then((position) => {
console.log(position);
})
.catch((err) => {
console.error(err.message);
});
@EdTimmer

Copy link
Copy Markdown

Thank you!

@alvarezaaronAI

Copy link
Copy Markdown

After hours of trying to solve it for my self. This freaking saved my life. I been at it for hours. THANK YOU!!

@JenniferWP

Copy link
Copy Markdown

Am I the only one who gets an error while trying to access position.coords ? It says Property 'coords' does not exist on type '{}'.

@charmingelle

Copy link
Copy Markdown

So elegant, thank you so much :)

@yuki0417

yuki0417 commented Sep 7, 2019

Copy link
Copy Markdown

Thank you! You save my time :}

@danprowse

Copy link
Copy Markdown

After trying to figure this out for a couple of hours, realised I needed a promise.. this solution worked great! thank you ๐Ÿ‘

@thamer-ben-dhafer

Copy link
Copy Markdown

Thank you

@dlik

dlik commented Jan 6, 2021

Copy link
Copy Markdown

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment