let lat, lat_1, lon, lon_1
if (getinfo_ip[1] !== undefined && getinfo_ip[2] !== undefined || getinfo_ip[1] !== null && getinfo_ip[2] !== null) {
request('http://ip-api.com/json/' + getinfo_ip[1], function (error, response, body) {
console.error('error:', error);
console.log('statusCode:', response && response.statusCode);
try {
let first_ip = JSON.parse(body)
lat = first_ip.lat
lon = first_ip.lon
} catch(err) {
console.error(err)
}
});
request('http://ip-api.com/json/' + getinfo_ip[2], function (error, response, body) {
console.error('error:', error);
console.log('statusCode:', response && response.statusCode);
try {
let second_ip = JSON.parse(body)
lat_1 = second_ip.lat
lon_1 = second_ip.lon
console.log(lat_1 + ' | ' + lon_1)
} catch(err) {
console.error(err)
}
});
console.log(lat + ' | ' + lon + ' | ' + lat_1 + ' | ' + lon_1)
в итоге, при выводе console.log(lat + ' | ' + lon + ' | ' + lat_1 + ' | ' + lon_1) в консоли вижу undefined, почему и как исправить?