Created
October 1, 2015 19:43
-
-
Save varmais/74586ec1854fe288d393 to your computer and use it in GitHub Desktop.
Geolocation to Promise wrap example
This file contains 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
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); | |
}); |
So elegant, thank you so much :)
Thank you! You save my time :}
After trying to figure this out for a couple of hours, realised I needed a promise.. this solution worked great! thank you 👍
Thank you
Thank you very much!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Am I the only one who gets an error while trying to access
position.coords
? It saysProperty 'coords' does not exist on type '{}'.