provider-geolocation
Declarative Geolocation API — request a position, read the result from attributes/state.
Features
- Attribute-driven Request + read a position through attributes
- User-gesture requests
is-paused+ the--requestcommand so permission prompts follow a click - One-shot or watch
watch-positionstreams updates instead of a single read
Installation
This package is available in the
<script src="https://unpkg.com/@excom/kit-utils@0.3.0/dist/index.umd.min.js"></script>
<script src="https://unpkg.com/@excom/neutron@0.2.0/dist/index.umd.min.js"></script>
<script src="https://unpkg.com/@excom/provider-geolocation@0.1.4/dist/index.umd.min.js"></script>npm install @excom/provider-geolocation<!-- import path to `node_modules` will depend on your build setup -->
<script type="module" src="/node_modules/@excom/provider-geolocation"></script>
<link rel="stylesheet" href="/node_modules/@excom/provider-geolocation">import "@excom/provider-geolocation";Peer dependencies (0)
Packages a consumer must install alongside this one. Workspace deps are bundled.
| Package | Version |
|---|---|
|
Usage
Requesting location on page load is poor UX (an unsolicited permission
prompt) — gate it behind a user gesture with is-paused and a trigger:
<button type="button" command="--request" commandfor="geo">
Share my location
</button>
<provider-geolocation id="geo" is-paused></provider-geolocation><button type="button" command="--request" commandfor="geo">
Share my location
</button>
<provider-geolocation id="geo" is-paused></provider-geolocation>API Reference
Attributes
Role —option is configurable, state
is managed by the element (read-only), or hybrid which is both.
Provision
Thisprovision property lives on the DOM node.
Read / watch it with Quark’s prop("provision"), or listen
for the neutron-provision event from app JS.
Events
Type
command event (HTML Command API): from a
<button command commandfor>, an <event-handler
command-name>, or a CommandEvent.
Recognized Elements
Child or descendant elements are recognized by and relevant to its functionality.Styles
@custom-selector synonyms so custom elements can share
semantic styles. Element aliases match the host tag / .tag-* class; state
aliases match attributes (nested under the element alias).
provider-geolocation
Attributes (8)
Role —option is configurable, state
is managed by the element (read-only), or hybrid which is both.
geo-timeout
Give up and fire
provider-geolocation-error after this many ms.
geoTimeout
number
"Infinity"high-accuracy
Request the most accurate position available (more battery / time cost).
highAccuracy
boolean
falseis-paused
Skip making a request on connect.
provider-geolocation-request still works while paused.
isPaused
boolean
falsemaximum-age
Accept a cached position up to this many ms old instead of requesting a fresh one. Ignored when
watch-position is set (always 0, i.e. no caching).
maximumAge
number
nullwatch-position
Keep requesting —
provider-geolocation-success fires on every position update instead of once. Uses navigator.geolocation.watchPosition under the hood.
watchPosition
boolean
falseis-error
The most recent request failed. Fires with the
error event.
isError
boolean
falseis-requesting
A position request is currently pending.
isRequesting
boolean
falseis-success
The most recent request resolved successfully. With
watch-position, stays set across updates.
isSuccess
boolean
falseProvision (1)
Thisprovision property lives on the DOM node.
Read / watch it with Quark’s prop("provision"), or listen
for the neutron-provision event from app JS.
provision
Latest result: the coords object on success, or the
GeolocationPositionError (or thrown error) on failure. Not reflected as an attribute.
provision
GeoSuccess
Events (3)
A "default action" is subsequent logic executed by the element if
e.preventDefault() is not
synchronously called on the event.
Type
provider-geolocation-error
Dispatched when the request fails (permission denied, timeout, position unavailable, or a thrown error).
Type
ProviderGeolocationErrorEvent
provision and sets is-error (clearing is-requesting / is-success).provider-geolocation-success
Dispatched on every successful position read (including each update while
watch-position is set).
Type
ProviderGeolocationSuccessEvent
provision and sets is-success (clearing is-requesting / is-error).
command event (HTML Command API): from a
<button command commandfor>, an <event-handler
command-name>, or a CommandEvent.
--request<button command="--request" commandfor="…">) while is-paused is set, or to force a fresh read at any time.
Recognized Elements (0)
Child or descendant elements are recognized by provider-geolocation and relevant to its functionality.Styles (0)
If you wish to opt-out of these styles on a case-to-case basis, use property
all: revert-layer.
Valence.css ships this as .unstyled and .unstyled-all for the entire tree.
@custom-selector synonyms so custom elements can share
semantic styles. Element aliases match the host tag / .tag-* class; state
aliases match attributes (nested under the element alias).
Release notes (1)
0.1.1
- Ship only dist (and declared extras) in the npm tarball; drop build logs, tests and sources
Release notes
A "default action" is subsequent logic executed by the element if
e.preventDefault() is not
synchronously called on the event.
If you wish to opt-out of these styles on a case-to-case basis, use property
all: revert-layer.
Valence.css ships this as .unstyled and .unstyled-all for the entire tree.