vinniegarcia / promised-location

Promise-compatible version of navigator.geolocation for use with react-native

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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!

About

Promise-compatible version of navigator.geolocation for use with react-native

License:MIT License


Languages

Language:JavaScript 100.0%