wheres-here
v1.0.1
Published
Promisified Geolocation
Downloads
3
Maintainers
Readme
Where is here?
🌏 Promisified Geolocation
Get current geolocation by Geolocation API as Promise.
Installation
Via Bower:
bower install wheres-here
Via NPM:
npm install wheres-here
Or Yarn:
yarn add wheres-here
Usage
You can bundle wheres-here
with webpack for using in browser.
const here = require('wheres-here');
here().then(position => {
let lat = position.coords.latitude;
let lng = position.coords.longitude;
console.log(`I'm at ${lat}, ${lng}.`); // Somewhere on the Earth.
}).catch(err => {
console.error(err); // Oh! It's error.
});
Or directly import to your webpage.
You can use unpkg CDN:
https://unpkg.com/wheres-here
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://unpkg.com/wheres-here"></script>
</head>
<body>
<script>
here().then(p => {
console.log(p);
}).catch(e => {
console.error(e);
});
</script>
</body>
</html>
API
here([options])
options
Type: PositionOptions
Return: Promise
Options for Geolocation.getCurrentPosition()