browser-geolocation

Wraps the Geolocation API as reactive state: the current position, derived coordinate selectors, the permission state, and a status machine. The watch starts on the first subscriber and stops on the last.

Permission & HTTPS
Geolocation requires a secure context (HTTPS or localhost) and a user grant. Subscribing to positionAtom (or a coordinate selector) triggers the browser's permission prompt.

Install

bun add @valdres/browser-geolocation

Live example

Loading demo…

Usage

import { createValue } from "valdres-solid"
import { coordsSelector } from "@valdres/browser-geolocation"

const coords = createValue(coordsSelector) // coords()

Exports

ExportKindType
positionAtomatom (read-only)GeolocationSnapshot | null
coordsSelectorselector{ latitude, longitude } | null
accuracySelectorselectornumber | null
altitudeSelector / speedSelector / headingSelectorselectornumber | null
permissionAtomatom (read-only)"granted" | "denied" | "prompt" | "unsupported"
geolocationStatusAtomatom (read-only)"idle" | "pending" | "active" | "error" | "unsupported"
geolocationErrorAtomatom (read-only)GeolocationError | null
geolocationOptionsAtomatom (settable)PositionOptions

Cross-framework

All state is global atoms/selectors, so it works in every framework — only the read primitive differs. Write geolocationOptionsAtom (via your framework's set hook, or store.set) to change accuracy/timeout options; the watch re-subscribes automatically.