Skip to content

Instantly share code, notes, and snippets.

@ChaseH88
Last active February 16, 2020 22:12
Show Gist options
  • Select an option

  • Save ChaseH88/4a2f49f3cc9832aab398db2b2302f56f to your computer and use it in GitHub Desktop.

Select an option

Save ChaseH88/4a2f49f3cc9832aab398db2b2302f56f to your computer and use it in GitHub Desktop.
Get Current Location
/**
* Get the current location inside of the
* browser window. Simply run the script,
* then enter the 'coordinates' variable
* to return your current location.
*/
const geo = navigator.geolocation;
let coordinates = null;
const showLocation = ({ coords }) => {
coordinates = {
lat: coords.latitude,
lon: coords.longitude
}
}
geo.getCurrentPosition(showLocation, (err) => new Error(err), {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment