1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-30 08:26:59 +02:00
joplin/ReactNativeClient/lib/geolocation-react.js

38 lines
856 B
JavaScript
Raw Normal View History

2017-12-14 20:12:14 +02:00
const Setting = require('lib/models/Setting.js');
2017-07-17 22:22:05 +02:00
2017-06-24 20:06:28 +02:00
class GeolocationReact {
2017-05-22 22:22:50 +02:00
static currentPosition_testResponse() {
return {
mocked: false,
timestamp: (new Date()).getTime(),
coords: {
speed: 0,
heading: 0,
accuracy: 20,
longitude: -3.4596633911132812,
altitude: 0,
latitude: 48.73219093634444
}
}
}
static currentPosition(options = null) {
2017-07-17 22:22:05 +02:00
if (Setting.value('env') == 'dev') return this.currentPosition_testResponse();
2017-05-22 22:22:50 +02:00
if (!options) options = {};
if (!('enableHighAccuracy' in options)) options.enableHighAccuracy = true;
if (!('timeout' in options)) options.timeout = 10000;
return new Promise((resolve, reject) => {
navigator.geolocation.getCurrentPosition((data) => {
resolve(data);
}, (error) => {
2017-09-12 20:01:15 +02:00
reject(error);
2017-05-22 22:22:50 +02:00
}, options);
});
}
}
2017-11-03 02:13:17 +02:00
module.exports = { GeolocationReact };