README
<x-geolocation>
Declarative Geolocation API as Web Components.
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)
});