I am fetching some data from an api, but I wish to use this data outside the fetch function but I am getting undefined. Below is my function for fetch
var result;
function reverseGeocoding(latitude, longitude) {
fetch("api_url"+latitude+longitude).then(
res => {
res.json().then(
data => {
result = data.features[0].place_name;
}
)
}
)
return result;
}
console.log(result);
How do I call reverseGeocoding
and store the results?