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.
- Host: GitHub
- URL: https://github.com/1000ch/x-geolocation
- Owner: 1000ch
- License: mit
- Created: 2014-09-18T10:18:04.000Z (over 11 years ago)
- Default Branch: main
- Last Pushed: 2023-03-14T17:37:50.000Z (over 3 years ago)
- Last Synced: 2024-05-02T05:56:00.677Z (about 2 years ago)
- Topics: geolocation, web-components
- Language: HTML
- Homepage: https://1000ch.github.io/x-geolocation
- Size: 886 KB
- Stars: 6
- Watchers: 4
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# x-geolocation 
> 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)