GithubHelp home page GithubHelp logo

billygl / vue-geolocation Goto Github PK

View Code? Open in Web Editor NEW

This project forked from scaccogatto/vue-geolocation

0.0 0.0 0.0 73 KB

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

License: MIT License

JavaScript 100.00%

vue-geolocation's Introduction

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.

vue-geolocation's People

Contributors

scaccogatto avatar sebastiansson avatar hkd987 avatar billygl avatar defji avatar gorbypark avatar pmioni avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.