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

https://github.com/1000ch/x-geolocation

Declarative Geolocation API as Web Components.
https://github.com/1000ch/x-geolocation

geolocation web-components

Last synced: 8 months ago
JSON representation

Declarative Geolocation API as Web Components.

Awesome Lists containing this project

README

          

# x-geolocation ![GitHub Actions Status](https://github.com/1000ch/x-geolocation/workflows/test/badge.svg)

> Declarative Geolocation API as Web Components.

## Install

Using [npm](https://www.npmjs.org/package/x-geolocation):

```sh
$ npm install x-geolocation
```

## Usage

Import `XGeolocation` and register it.

```html

import XGeolocation from 'https://unpkg.com/x-geolocation';

customElements.define('x-geolocation', XGeolocation);

```

Put `` tag.

```html

```

### Monitoring position change

To monitor position changing, execute `monitorPosition()` function.

```js
document.querySelector('x-geolocation').monitorPosition();
```

Or set `monitor` attribute.

```html

```

### Handle position changes

Handle `positionchange` event using `addEventListener()`.

```js
document.querySelector('x-geolocation').addEventListener('positionchange', e => {
console.log('latitude:', e.detail.latitude);
console.log('longitude:', e.detail.longitude)
});
```

## License

[MIT](https://1000ch.mit-license.org) © [Shogo Sensui](https://github.com/1000ch)