Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gluons/wheres-here
🌏 Promisified Geolocation
https://github.com/gluons/wheres-here
geolocation javascript promise
Last synced: about 2 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 (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-07-20T09:13:25.000Z (over 4 years ago)
- Last Synced: 2024-11-07T20:49:17.800Z (2 months 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?
[![license](https://img.shields.io/github/license/gluons/wheres-here.svg?style=flat-square)](https://github.com/gluons/wheres-here/blob/master/LICENSE)
[![npm](https://img.shields.io/npm/v/wheres-here.svg?style=flat-square)](https://www.npmjs.com/package/wheres-here)
[![Bower](https://img.shields.io/bower/v/wheres-here.svg?style=flat-square)](https://github.com/gluons/wheres-here)
[![Travis](https://img.shields.io/travis/gluons/wheres-here.svg?style=flat-square)](https://travis-ci.org/gluons/wheres-here)
[![ESLint Gluons](https://img.shields.io/badge/code%20style-gluons-9C27B0.svg?style=flat-square)](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/):**
[![NPM](https://nodei.co/npm/wheres-here.png?downloads=true&downloadRank=true&stars=true)](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)