hi im trying to use a simple api to to enter a city name and get the lat and lon of it i made this function which works fine but when i want to return the value to use it outside the function it returnes undefined. here is the code:
let city = "London"
let values = getWeatherData(city, "en");
console.log(values)
function getWeatherData(city, lang) {
fetch('http://api.openweathermap.org/geo/1.0/direct?q='+city+'&limit=1&appid={My_API_Key}')
.then(response => response.json())
.then(data => {
var cityCountryname = data[0]['country']
var cityName = data[0]['local_names'][lang]
var cityLat = data[0]['lat']
var cityLon = data[0]['lon']
// console.log(cityCountryname)
return[
cityCountryname,
cityName,
cityLat,
cityLon
];
})
.catch(console.log("wrong"))
}