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