Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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)