promised-location

1.0.1 • Public • Published

promised-location

npm version travis build information Coverage Status

Promise-compatible version of navigator.geolocation. Compatible with react native!

Usage

PromisedLocation works like navigator.geolocation.getCurrentPosition, except instead of supplying callbacks for the success and error scenarios, you handle a standard Promise. Call new PromisedLocation with PositionOptions, then handle like any other promise with then and catch.

var PromisedLocation = require('promised-location');
 
var options = {
    enableHighAccuracy: true,
    timeout: 10000,
    maximumAge: 60000
};
 
var locator = new PromisedLocation(options);
locator
    .then(function (position) {
        console.log(position.coords);
    })
    .catch(function (err) {
        console.error('Position Error ', err.toString());
    });

FAQ

  1. What if my browser/environment doesn't support geolocation?

The returned Promise will be rejected.

  1. What are the default values for PositionOptions?

Default PositionOptions are the same as the Web API, namely:

{
  enableHighAccuracy: false,
  timeout: Infinity,
  maximumAge: 0
}

Questions? Comments? Fixes?

File an issue or submit a pull request!

Readme

Keywords

Package Sidebar

Install

npm i promised-location

Weekly Downloads

35

Version

1.0.1

License

MIT

Last publish

Collaborators

  • vinniegarcia