Skip to content

Instantly share code, notes, and snippets.

@aperkaz
Created June 23, 2020 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aperkaz/547fb1ce3110da8e332c2fc6b0405699 to your computer and use it in GitHub Desktop.
Save aperkaz/547fb1ce3110da8e332c2fc6b0405699 to your computer and use it in GitHub Desktop.
Get host lat-long in electron.js
(async () => {
const got = require("got");
const publicIp = require("public-ip");
// get public ip
const publicIpV4 = await publicIp.v4();
// get location from ip
try {
const response = await got(`http://ip-api.com/json/${publicIpV4}`);
const { lat, lon } = JSON.parse(response.body);
console.log(`lat: ${lat}, lon: ${lon}`);
} catch (error) {
console.log(error.response.body);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment