https://github.com/gluons/wheres-here
🌏 Promisified Geolocation
https://github.com/gluons/wheres-here
geolocation javascript promise
Last synced: 12 months ago
JSON representation
🌏 Promisified Geolocation
- Host: GitHub
- URL: https://github.com/gluons/wheres-here
- Owner: gluons
- License: mit
- Created: 2017-01-12T10:35:57.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-07-20T09:13:25.000Z (about 6 years ago)
- Last Synced: 2025-02-15T04:07:56.389Z (over 1 year ago)
- Topics: geolocation, javascript, promise
- Language: JavaScript
- Homepage:
- Size: 354 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Where is here?
[](https://github.com/gluons/wheres-here/blob/master/LICENSE)
[](https://www.npmjs.com/package/wheres-here)
[](https://github.com/gluons/wheres-here)
[](https://travis-ci.org/gluons/wheres-here)
[](https://github.com/gluons/eslint-config-gluons)
🌏 Promisified Geolocation
Get current geolocation by [Geolocation API](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation) as [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Installation
**Via [Bower](https://bower.io/):**
```
bower install wheres-here
```
**Via [NPM](https://www.npmjs.com/):**
[](https://www.npmjs.com/package/wheres-here)
```
npm install wheres-here
```
**Or [Yarn](https://yarnpkg.com/):**
```
yarn add wheres-here
```
## Usage
You can bundle `wheres-here` with [webpack](https://github.com/webpack/webpack) for using in browser.
```javascript
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):
```
https://unpkg.com/wheres-here
```
```html
Document
here().then(p => {
console.log(p);
}).catch(e => {
console.error(e);
});
```
## API
### here([options])
#### options
Type: [`PositionOptions`](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions)
Return: [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
Options for [`Geolocation.getCurrentPosition()`](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition)