Skip to content

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

License

Notifications You must be signed in to change notification settings

vinniegarcia/promised-location

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published