0

I'm trying to find the coordinates (latitude and longitude) from the Google Geocoding API but I can't figure out how to access the properties within the object I am returning. This is the code:

const geoCoor = async function () {
  const url = `https://maps.googleapis.com/maps/api/geocode/json?address=${address}&key=${API_KEY}`;
  const response = await request.get(url);
  return response
};

(async function(){
  let data = await geoCoor();
  console.log(data.results[0]);
})();

I've tried wrapping it in an IIFE, but when I try to access the array, I am still getting the "undefined" error message.
Bmurphy
  • 54
  • 5
  • Either put the code inside `geoCoor`, or call `.then` on the Promise outside – CertainPerformance Jan 09 '21 at 15:16
  • @CertainPerformance in addition, it's possible to use `await getCoor()` if the call is in an async function or a top level async module (although the support for the latter is spotty). – VLAZ Jan 09 '21 at 15:26
  • @VLAZ I tried awaiting geoCoor() in an IIFE, but I'm still struggling to get the actual results in a variable – Bmurphy Jan 09 '21 at 16:38

0 Answers0