promised-location
v1.0.1
Published
promisified geolocation library
Downloads
141
Readme
promised-location
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
- What if my browser/environment doesn't support geolocation?
The returned Promise
will be rejected.
- 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!