/**
* GeoIP API
* GET https://api.globus.studio/v2/geo?ip=8.8.8.8&format=json
* GET https://api.globus.studio/v2/geo?ip=8.8.8.8&full=true&format=json
* Response: { country } or { country, city, region, latitude, longitude, region_name }
*/
async function getGeo(ip, full = false) {
const url = new URL('https://api.globus.studio/v2/geo');
url.searchParams.set('ip', ip);
url.searchParams.set('format', 'json');
if (full) url.searchParams.set('full', 'true');
const res = await fetch(url);
return res.json();
}
// Country only
getGeo('8.8.8.8').then(d => console.log(d.country));
// Full geo info
getGeo('8.8.8.8', true).then(d => console.log(d.city, d.region_name, d.latitude, d.longitude));