1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/packages/app-mobile/utils/geolocation-react.js

43 lines
940 B
JavaScript
Raw Normal View History

import Geolocation from '@react-native-community/geolocation';
const Setting = require('@joplin/lib/models/Setting').default;
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,
2019-07-29 15:43:53 +02:00
timestamp: new Date().getTime(),
2017-05-22 22:22:50 +02:00
coords: {
speed: 0,
heading: 0,
accuracy: 20,
longitude: -3.45966339111328,
2017-05-22 22:22:50 +02:00
altitude: 0,
2019-07-29 15:43:53 +02:00
latitude: 48.73219093634444,
},
};
2017-05-22 22:22:50 +02:00
}
static currentPosition(options = null) {
if (Setting.value('env') === 'dev') return this.currentPosition_testResponse();
2017-07-17 22:22:05 +02:00
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) => {
Geolocation.getCurrentPosition(
data => {
2019-07-29 15:43:53 +02:00
resolve(data);
},
error => {
2019-07-29 15:43:53 +02:00
reject(error);
},
options,
2019-07-29 15:43:53 +02:00
);
2017-05-22 22:22:50 +02:00
});
}
}
2019-07-29 15:43:53 +02:00
module.exports = { GeolocationReact };