Skip to content

Instantly share code, notes, and snippets.

@omas-public
Created November 12, 2019 10:23
Show Gist options
  • Save omas-public/1a428632ea7df1e1cbcd13dd8cb056ae to your computer and use it in GitHub Desktop.
Save omas-public/1a428632ea7df1e1cbcd13dd8cb056ae to your computer and use it in GitHub Desktop.
const getCurrentPosition = async () => {
const geolocation = options => new Promise((resolve, reject) =>
navigator.geolocation.getCurrentPosition(resolve, reject, options)
)
const options = { enableHighAccuracy: true }
const position = await geolocation(options)
.then(json => json.coords)
.then(coords => ({ latitude: coords.latitude, longitude: coords.longitude }))
.catch(error => console.log(error))
return position
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment