1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-04-20 11:28:40 +02:00
joplin/ReactNativeClient/lib/geolocation-node.js

27 lines
633 B
JavaScript
Raw Normal View History

2018-03-09 17:49:35 +00:00
const { shim } = require("lib/shim.js");
const { netUtils } = require("lib/net-utils.js");
2017-07-10 18:09:58 +00:00
class GeolocationNode {
static async currentPosition(options = null) {
if (!options) options = {};
const ip = await netUtils.ip();
2018-03-09 17:49:35 +00:00
let response = await shim.fetch("https://freegeoip.net/json/" + ip);
if (!response.ok) throw new Error("Could not get geolocation: " + (await response.text()));
2017-07-10 18:09:58 +00:00
response = await response.json();
return {
2018-03-09 17:49:35 +00:00
timestamp: new Date().getTime(),
2017-07-10 18:09:58 +00:00
coords: {
longitude: response.longitude,
altitude: 0,
2018-03-09 17:49:35 +00:00
latitude: response.latitude,
},
};
2017-07-10 18:09:58 +00:00
}
}
2018-03-09 17:49:35 +00:00
module.exports = { GeolocationNode };