x-geolocation

Declarative Geolocation API as Web Components.

Usage no npm install needed!

<script type="module">
  import xGeolocation from 'https://cdn.skypack.dev/x-geolocation';
</script>

README

<x-geolocation>

Declarative Geolocation API as Web Components.

Build Status NPM version devDependency Status

Install

Using npm:

$ npm install x-geolocation

Usage

Import XGeolocation and register it.

<script type="module">
import XGeolocation from 'https://unpkg.com/x-geolocation';

customElements.define('x-geolocation', XGeolocation);
</script>

Put <x-geolocation> tag.

<x-geolocation></x-geolocation>

Monitoring position change

To monitor position changing, execute monitorPosition() function.

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

Or set monitor attribute.

<x-geolocation monitor></x-geolocation>

Handle position changes

Handle positionchange event using addEventListener().

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

License

MIT © Shogo Sensui