Created
June 23, 2020 10:03
-
-
Save aperkaz/547fb1ce3110da8e332c2fc6b0405699 to your computer and use it in GitHub Desktop.
Get host lat-long in electron.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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