Created
March 28, 2019 11:41
-
-
Save CEOehis/eb72e2c4f27131853ea2ff242cd99da2 to your computer and use it in GitHub Desktop.
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
| function getCurrentPosition() { | |
| if (navigator.geolocation) { | |
| return new Promise((resolve, reject) => { | |
| navigator.geolocation.getCurrentPosition(resolve, reject); | |
| }); | |
| } else { | |
| return Promise.reject('geolocation is not available on this device'); | |
| } | |
| } | |
| // then to use getCurrentPosition | |
| getCurrentPosition() | |
| .then((position) => { | |
| console.log('position', position); // logs position object https://developer.mozilla.org/en-US/docs/Web/API/Position | |
| }) | |
| .catch((error) => { | |
| // error obtaining user location | |
| console.log(error) // geolocation is not available on this device | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment