npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vue-browser-geolocation

v3.0.1

Published

Tiny, type-safe Geolocation for Vue 3 — a reactive useGeolocation() composable and standalone Promise-based helpers.

Downloads

6,691

Readme

vue-browser-geolocation

Tiny, type-safe Geolocation for Vue 3 — a reactive useGeolocation() composable and standalone Promise-based helpers.

npm version CI minzipped size license

  • Reactive composableuseGeolocation() for <script setup>; auto-clears watches on unmount.
  • Reactive streamingcoords updates on every position fix, not just the first.
  • Real errors — rejects with the full GeolocationPositionError so you can branch on error.code.
  • Type-safe — written in TypeScript, ships .d.ts. ESM + CJS builds.
  • Lightweight — zero runtime dependencies, vue is a peer dependency.

Install

npm install vue-browser-geolocation
# or
pnpm add vue-browser-geolocation
# or
yarn add vue-browser-geolocation

Requires Vue 3 (^3.2.25).

Composable (recommended)

<script setup lang="ts">
import { useGeolocation } from 'vue-browser-geolocation'

const { coords, error, isWatching, getLocation, watchLocation, clearWatch } =
  useGeolocation({ enableHighAccuracy: true })

// one-shot
async function locate() {
  await getLocation()
  console.log(coords.value) // { lat, lng, accuracy, ... }
}

// continuous — coords.value updates on every fix
watchLocation()
</script>

<template>
  <p v-if="error">Error {{ error.code ?? '' }}: {{ error.message }}</p>
  <p v-else-if="coords">{{ coords.lat }}, {{ coords.lng }}</p>
  <button @click="locate">Locate me</button>
  <button v-if="isWatching" @click="clearWatch">Stop watching</button>
</template>

useGeolocation() returns reactive refs and automatically clears the active watch when the component unmounts.

| Field | Type | Description | | --- | --- | --- | | coords | Ref<Coordinates \| null> | Latest fix, null before the first one. | | error | Ref<GeolocationError \| null> | Latest error (full object), null when fine. | | isWatching | Ref<boolean> | Whether a watch is active. | | getLocation(options?) | Promise<Coordinates> | One-shot fetch; updates coords/error. | | watchLocation(options?) | number \| undefined | Starts a watch, returns its watchID. | | clearWatch() | void | Stops the active watch. |

Standalone functions

Everything is also importable directly, no Vue instance required:

import {
  getLocation,
  watchLocation,
  clearWatch,
  isSupported,
} from 'vue-browser-geolocation'

Coordinates

interface Coordinates {
  lat: number
  lng: number
  altitude: number | null
  altitudeAccuracy: number | null
  accuracy: number
  heading: number | null
  speed: number | null
}

Options

See PositionOptions{ enableHighAccuracy?, timeout?, maximumAge? }.

Testing escape hatch

getLocation and watchLocation accept a trailing forceReject flag. When true, the promise rejects immediately with a GeolocationForcedRejectError, letting you exercise failure paths without touching the real device API:

await getLocation({}, true) // rejects
await watchLocation({}, undefined, true) // rejects

Migrating from v2 (plugin API)

v3 drops the VueGeolocation plugin and the $getLocation / $watchLocation / $clearLocationWatch global properties — use useGeolocation() or the standalone functions directly.

Migrating from v1 (Vue 2)

v2/v3 target Vue 3 only. Breaking changes from v1:

| v1 (Vue 2) | v3 (Vue 3) | | --- | --- | | Vue.use(VueGeolocation) | use useGeolocation() composable | | reject(error.message) (string) | reject(error) — full GeolocationPositionError; read error.code | | $watchLocation() resolved once | watchLocation(options, onUpdate) resolves with { watchID, coordinates } and streams via onUpdate (#15) | | no composable | reactive useGeolocation() | | plain JS, no types | TypeScript, ships .d.ts |

If you cannot migrate to Vue 3 yet, stay on [email protected].

License

MIT © Marco Boffo