vue-browser-geolocation

1.8.0 • Public • Published

vue-geolocation

ask to your users their coordinates, and wrap them into a Promise

Build Status

Plugin install

yarn add vue-browser-geolocation

or

npm install vue-browser-geolocation

in your main.js

import VueGeolocation from 'vue-browser-geolocation';
Vue.use(VueGeolocation);

Usage

Inside a Vue Component

this.$getLocation(options)
  .then(coordinates => {
    console.log(coordinates);
  });

Will prompt a Geolocation Request

or to watch a location

this.$watchLocation(options)
  .then(coordinates => {
    console.log(coordinates);
  })

you can clear the watcher

this.$clearLocationWatch(watchID)

please refer to the Geolocation docs to reference how to get a watchID

Options

See PositionOptions

Example

this.$getLocation({
    enableHighAccuracy: bool, //defaults to false
    timeout: Infinity, //defaults to Infinity
    maximumAge: int //defaults to 0
    
})
  .then(coordinates => {
    console.log(coordinates);
  });

Forcing failure in automated testing

If you need to setup automated testing in your application, and you need to force failure of geolocation to test how your application behaves, you can pass a second argument (forceReject) to this.$getGelocation and this.$watchLocation:

this.$getLocation(positionOptions, forceReject)

this.$watchLocation(positionOptions, forceReject)

if the parameter is true, the promise will be rejected with a special error message.

Dependencies (1)

Dev Dependencies (6)

Package Sidebar

Install

npm i vue-browser-geolocation

Weekly Downloads

3,266

Version

1.8.0

License

MIT

Unpacked Size

10.2 kB

Total Files

9

Last publish

Collaborators

  • marco-gatto-boffo