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 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-geolocation-api

v0.1.21

Published

A simple reactive wrapper for [Geolocation Web API](https://developer.mozilla.org/pt-BR/docs/Web/API/Geolocation)

Downloads

1,627

Readme

Vue Geolocation API

A simple reactive wrapper for Geolocation Web API

Features

  • Customizable
  • Reactive geolocation position
  • Simple watcher control
  • SSR Compatibility
  • GeoJSON output

Setup

Install with npm

npm install --save vue-geolocation-api

Install with yarn

yarn add vue-geolocation-api

Vue instance

import Vue from 'vue'
import VueGeolocationApi from 'vue-geolocation-api'

Vue.use(VueGeolocationApi/*, { ...options } */)

Nuxt

Add to modules section at your nuxt.config.js

module.exports =  {
  modules:  [
    'vue-geolocation-api/nuxt',
  ],
  geolocation:  {
    // watch: true,
  },
}

Usage

Computed properties

export default {
  // ...
  computed: {
    inRange() {
      const coords = this.$geolocation.coords
      if (!coords) return '?'
      return distanceFrom(coords, this.destination) > 150
    }
  }
}

Note that distanceFrom is not included in this package, if you need this feature I recommend to use with @turf/distance or geo-distance

Component templates

<template>
  <div>
    <span v-if="$geolocation.loading">Loading location...</span>
    <span v-else-if="!$geolocation.supported">Geolocation API is not supported</span>
    <span v-else>Range from destination: {{ inRange ? 'Allowed' : 'Disallowed' }}</span>
  </div>
</template>

Watch statements

export default {
  // ...
  watch: {
    inRange(reached) {
      if (reached !== true) return
      console.log('Congratulations, you arrived')
      this.$geolocation.watch = false // Stop watching location
    }
  }
}

Outputs

$geolocation.position [Position]

Exposes the results from getCurrentPosition or the last result from watchPosition. Default or unavailable: null

$geolocation.loading [Boolean]

If true, means the location is currently being executed.

$geolocation.supported [Boolean]

If true means the location api is available in the browser. If false means the location api is not available in the browser. if null means the support wasn't verified yet.

$geolocation.coords [Coordinates]

Alias for $geolocation.position.coords Default or unavailable: null

$geolocation.timestamp [Timestamp]

Alias for $geolocation.position.timestamp Default or unavailable: null

$geolocation.geoJSON [GeoJSON Point]

Formatted coordinates. Default or unavailable: null

Options

$geolocation.watch [Boolean]

If true will initiate watchPosition. If false stop watchPosition. This property can be changed dynamically and will react to it's changes.

$geolocation.options [PositionOptions]

Defines the parameters that will be used by getCurrentPosition and watchPosition. Changing this property will trigger an watchPosition reload if currently watching. Important: This property is only reactive if you replace it entirely. If you just want to change one options check the method setOption

Methods

$geolocation.getCurrentPosition(?options) [Promised Position]

Simply wraps the navigator.geolocation.getCurrentPosition as a Promise.

$geolocation.setOption(key, value) [Undefined]

Reactively updates the key property in $geolocation.options with value.

$geolocation.checkSupport() [Boolean]

Forces the $geolocation.supported to update.

Contributing or Issuing

Coming soon...

Created by @SkyaTura